• 关于反射


    公共语言运行库加载管理应用程序域,包括每个程序集加载到相应应用程序域以及控制每个程序集中类型层次结构的内存布局.
    程序集包括模块,模块又包含类型,类型包含成员,反射则提供了封装程序集,模块,类型的对象。可以使用反射动态创建程序集的实例,将类型绑定到现有对象上,或从现有对象中获取类型。可以调用类型的方法,字段和属性。

    示例代码:
    public void init_Ref()
        {
            Assembly ab 
    = Assembly.LoadFrom(@"D:\my_project\MmyeeAd\BLL\bin\Debug\LTP.Common.dll");
            
    //装载组件
            foreach (Type t in ab.GetTypes())
            {
                
    if (t.IsClass && t.IsAbstract)
                {
                    MethodInfo[] miArr 
    = t.GetMethods();
                    
    object o = Activator.CreateInstance(t);//创建实例 
                    
    //创建无参构造函数
                    foreach (MethodInfo m in miArr)
                    {
                        
    if (m.IsAbstract && m.IsStatic && m.GetParameters().Length == 0)
                        {
                            
    object re = m.Invoke(o, null);
                            Response.Write(m.Name 
    + "," + re+"<br>");
                        }
                    }
                }
            }
        }
  • 相关阅读:
    # GIT团队实战博客
    # ML学习小笔记—Where does the error come from?
    # Alpha冲刺3
    # Alpha冲刺2
    # Alpha冲刺1
    # ML学习小笔记—Linear Regression
    # 需求分析报告
    # 团队UML设计
    # 团队选题报告
    Alpha 冲刺 (4/10)
  • 原文地址:https://www.cnblogs.com/jinweida/p/1126141.html
Copyright © 2020-2023  润新知