namespace AssemblyDemo
{
class Program
{
static void Main(string[] args)
{
//通过反射动态调用另一个程序集中的方法
//1加载程序集
string path = AppDomain.CurrentDomain.BaseDirectory;//获取当前.exe执行文件的路径
path = Path.Combine(path, "MyAssembly.dll");//拼接程序集的路径
Assembly assembly = Assembly.LoadFile(path);
//2创建Person类的对象
Type type = assembly.GetType("MyAssembly.Person");
object o = Activator.CreateInstance(type,"wolf",22,"未知");//实例化
//3获取方法的类型
MethodInfo methodInfo = type.GetMethod("SayHi");
//4反射调用方法
methodInfo.Invoke(o, null);
Console.Read();
}
}
}
结果:
未完待续。。。。。











