反射的使用

https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.loadmodule?view=netframework-4.8#System_Reflection_Assembly_LoadModule_System_String_System_Byte___

// 在invoke的时间非静态方法需要一个目标, 则需要Object 参数
// typeof()  ,GetType(string st) GetMethod(string st)  如果这两个方法中的参数所在命名空间与程序集名称不符,则需要加上命名空间, 如下"T.Class1"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
[assembly: AssemblyVersion("1.0.2000.0")]

 namespace T {  
    class Program
    {
        static void Main(string[] args)
        {
            Assembly assem = typeof(Class1).Assembly;
            Console.WriteLine(assem.FullName);

            Object o = assem.CreateInstance("T.Class1", false, BindingFlags.ExactBinding, null, new Object[] { "Hello" }, null, null);
            Type t = assem.GetType("T.Class1");
            MethodInfo m = t?.GetMethod("Test",new[] { typeof(string) });
            Object ob=m?.Invoke(null, new Object[] { "ell" });

            Console.WriteLine("\nAssembly entry point:");
            Console.WriteLine(assem.EntryPoint);

            Console.ReadKey();
        }
    }
}

 

 

 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace T
{

    public class Class1
    {
         string xx;
        public void Test(string st)
        {
            Console.WriteLine(st+xx);

        }

        public Class1(string x)
        {
            xx = x;
        }
    }
}

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值