反射简单使用

 //Type p = Type.GetType("TypeTry.TestClass");
            //Type pp = Type.GetType("WebApplication2.Person");
            Assembly assembly = Assembly.Load("TypeTry");
            //foreach (Type aa in assembly.GetTypes())
            //{
            //    Response.Write(aa.Name);
            //}
            Type p = assembly.GetType("TypeTry.TestClass");
            object[] constuctParms = new object[] { "timmy" };
            object obj = Activator.CreateInstance(p, constuctParms);

            PropertyInfo property = p.GetProperty("Value");
            property.SetValue(obj,"times",null);
            object objPro = property.GetValue(obj,null);
            MethodInfo method = p.GetMethod("GetValue");
            BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
            //GetValue方法的参数
            object[] parameters = new object[] { "Hello" };
            //调用方法,用一个object接收返回值
            //object returnValue = method.Invoke(obj, flag, Type.DefaultBinder, parameters, null);
            object returnValue = method.Invoke(obj, parameters);
            Response.Write(returnValue.ToString());

原文地址:https://www.cnblogs.com/fulai/p/3299029.html