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

  • 相关阅读:
    L208
    L207
    L206
    L205 EE
    L204
    监控glusterfs
    监控elssticSearch健康状态
    防火墙
    创建逻辑卷
    编译安装nginx,并使用systemd管理nginx
  • 原文地址:https://www.cnblogs.com/fulai/p/3299029.html
Copyright © 2011-2022 走看看