zoukankan      html  css  js  c++  java
  • 反射简单使用

     //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());

  • 相关阅读:
    ES6 Promise 对象及解决回调地狱问题
    ES6 Iterator迭代器和for...of循环
    ES6 Reflect反射
    ES6 Proxy代理
    ES6 Map对象与Set对象
    端口隔离的应用场景与配置
    交换机级联,堆叠,集群技术介绍
    OSPF虚连接简单配置
    小结ospf基本配置的三个参数
    静态路由配置的3个参数
  • 原文地址:https://www.cnblogs.com/fulai/p/3299029.html
Copyright © 2011-2022 走看看