• 反射代码示例


    namespace CLib
    {
    public interface ITest
        {
            void SysTest();
        }

     public class Test : ITest
        {
            public void SysTest()
            {
                System.Console.WriteLine("Hello Reflection");
            }
        }
    }

    class Program
        {
            static void Main(string[] args)
            {
                Assembly ass = System.Reflection.Assembly.LoadFrom("CLib.dll");
                Type type = ass.GetType("CLib.Test");
                Type type1 = System.Activator.CreateInstanceFrom("CLib.dll", "CLib.Test").GetType();
                Type type2 = System.Activator.CreateInstanceFrom("CLib.dll", "CLib.Test").Unwrap().GetType();

                Console.WriteLine(type.ToString());
                Console.WriteLine(type1.ToString());
                Console.WriteLine(type2.ToString());
                Console.WriteLine("=============================");
                
                CLib.ITest test = (CLib.ITest)System.Activator.CreateInstance("CLib", "CLib.Test").Unwrap();
                test.SysTest();

                Console.WriteLine("=============================");
                Console.ReadLine();
            }
        }

  • 相关阅读:
    模板方法模式
    LINQ多条件OR模糊查询
    在LINQ中实现多条件联合主键LEFT JOIN
    js只显示整点
    Vue-cli2中处理跨域
    vue动态绑定类(实现tab)
    Vue中引入cdn同时防止cdn挂掉
    vue+nginx开启gzip压缩
    Vue路由守卫
    vue-router嵌套路由和二级目录(域名)
  • 原文地址:https://www.cnblogs.com/RobotTech/p/978459.html
Copyright © 2020-2023  润新知