ahjesus约束方法或属性的调用方

    class Program {
        static void Main(string[] args) {
            test();
            run();
            Console.ReadKey();
        }

        static void run() {
            test();
        }

        static void test() {
            var method = new StackFrame(1).GetMethod();
            if (method.Name=="run")
            {
                Console.WriteLine("不允许被run调用");
            }
            else {
                Console.WriteLine("test成功");
            }
        }
    }
原文地址:https://www.cnblogs.com/ahjesus/p/3469845.html