zoukankan      html  css  js  c++  java
  • 反射代码示例

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

  • 相关阅读:
    Spring Security和Swagger2集成报错
    [转] SpringBoot返回json 数据以及数据封装
    ElasticSearch问题总结
    Linux基础命令
    Jenkins总结3-shell脚本
    Jenkins总结2-部署maven项目
    SpringCloud启动异常Stopping service [Tomcat]
    索引使用场景
    flask app.config
    python验证企业统一信用码
  • 原文地址:https://www.cnblogs.com/RobotTech/p/978459.html
Copyright © 2011-2022 走看看