C#反射 创建对象,调用方法

namespace TestReflection
{
public class MyCls
{
public void Fun()
{
Console.WriteLine(
"MyCls.Fun invoke.");

}
}
}
/////////////////////////////////////////////////////////
...

using System.Reflection;

namespace TestReflection
{
class Program
{
static void Main(string[] args)
{
Type type
= Assembly.Load("TestReflection").GetType("TestReflection.MyCls");
object obj= Activator.CreateInstance(type);
type.InvokeMember(
"Fun", BindingFlags.Default | BindingFlags.InvokeMethod,
null, obj, new object[] { });

Console.ReadKey();
}
}
}
原文地址:https://www.cnblogs.com/wucg/p/1766266.html