//加载dll库
Assembly dll = Assembly.LoadFile(@"E:\whq\code\Test\DLLConsole\bin\Debug\Test.UI.dll");
//获取所有类型(类、接口……)
Type[] typeClass = dll.GetTypes();
foreach (Type t in typeClass)
{
//获取所有公共成员
FieldInfo[] fields = t.GetFields();
//获取所有公共方法
MethodInfo[] methods = t.GetMethods();
}
//获取指定类
Type type=dll.GetType("Test.UI.Class2");
//获取指定方法
MethodInfo method = type.GetMethod("Run");
//创建类型实例
object obj= Activator.CreateInstance(type);
//调用方法Run(int i) returnValue为返回值
object returnValue= method.Invoke(obj, new object[] { 1 });
Assembly dll = Assembly.LoadFile(@"E:\whq\code\Test\DLLConsole\bin\Debug\Test.UI.dll");
//获取所有类型(类、接口……)
Type[] typeClass = dll.GetTypes();
foreach (Type t in typeClass)
{
//获取所有公共成员
FieldInfo[] fields = t.GetFields();
//获取所有公共方法
MethodInfo[] methods = t.GetMethods();
}
//获取指定类
Type type=dll.GetType("Test.UI.Class2");
//获取指定方法
MethodInfo method = type.GetMethod("Run");
//创建类型实例
object obj= Activator.CreateInstance(type);
//调用方法Run(int i) returnValue为返回值
object returnValue= method.Invoke(obj, new object[] { 1 });