示例#1
0
        static void Main(string[] args)
        {
            Action putLine = () => { Console.Write("\n"); };

            "Demonstrating Reflection".title('=');
            putLine();

            "Reflecting on ReflectionTest class".title();
            putLine();

            ReflectionTest rt = new ReflectionTest();

            ReflectionDemo.showTypeDetails(rt);
            putLine();

            "Reflecting on ReflectionTest's delegate sayHandler".title();
            putLine();

            Program pr = new Program();

            rt.sayHandler += new ReflectionTest.SayHandler(pr.handleNotifications);
            ReflectionDemo.showTypeDetails(rt.sayHandler);
            putLine();

            "Invoking lambda defined in main".title();
            putLine();

            string localMsg           = " and localMsg";
            Action <string, bool> act = (msg, boolValue) => {
                Console.Write("\n  this is lambda invocation: \"{0}\"", msg + localMsg);
                Console.Write("\n  second argument is {0}", boolValue);
            };

            act.Invoke("lambda argument", true);
            putLine();

            "Reflecting on lamda bound to Action<string>".title();
            putLine();
            ReflectionDemo.showTypeDetails(act);

            "Reflecting on Action's Target".title();
            putLine();
            ReflectionDemo.showTypeDetails(act.Target);
        }