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

  • 相关阅读:
    线段树【加强】
    ATM(BZOJ 1179)
    Trick or Treat on the Farm
    欧拉回路 HDU
    无序字母对(luogu 1314)
    MooFest
    Snowflake Snow Snowflakes(POJ 3349)
    Firetruck(UVA 208)
    B进制星球(luogu 1604)
    遍历一个树的所有子节点,画出该树,深度不定,广度不定,适用于任何树,深度优先算法
  • 原文地址:https://www.cnblogs.com/fulai/p/3299029.html
Copyright © 2011-2022 走看看