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

  • 相关阅读:
    Spring Bean(一)
    Spring IOC(一)
    三种常用的查找算法
    分布式架构的一致性
    Java内存区域笔记(一)
    分组交换和电路交换
    Python说文解字_Python之多任务_03
    Python说文解字_Python之多任务_02
    Python说文解字_Python之多任务_01
    Python说文解字_杂谈09
  • 原文地址:https://www.cnblogs.com/fulai/p/3299029.html
Copyright © 2011-2022 走看看