反射

反射是为了程序在运行时程序能获取到一些关于程序集(assembly),class,method,property的一些信息的 这样的机制

反射相当于一种进程,这种进程可以修改自己机构和行为的一种能力.

string s = "Hello Reflection";
            Type t = s.GetType();
            Console.WriteLine(t.FullName);
            Type t2 = Type.GetType("system.string", false, true);
            Console.WriteLine(t2.FullName);
            Type t3 = typeof(string);
            Console.WriteLine(t3.FullName);
            Console.ReadLine();
        static void Main(string[] args)
        {
            string s = "Hello Reflection";
            Type t = s.GetType();
            Console.WriteLine(t.FullName);
            Type t2 = Type.GetType("system.string", false, true);
            Console.WriteLine(t2.FullName);
            Type t3 = typeof(string);
            Console.WriteLine(t3.FullName);
            //GetMothods(t3);
            Console.WriteLine(t3.GetMethod("Copy"));
            Console.ReadLine();

        }
        public static void GetMothods(Type t)
        {
            MethodInfo[] mti = t.GetMethods();
            foreach (MethodInfo m in mti)
            {
                Console.WriteLine("type:{0}", m.Name);
            }
        }

//getmethod getmethods gettype getproperty 都是反射

原文地址:https://www.cnblogs.com/handsomer/p/4554087.html