Assembly
程序集类,主要用来加载其它程序集,加载后,才能用Type来使用其它程序集中的信息,如果想要使用不是自己程序集中的内容 需要先加载程序集,比如 dll文件(库文件) 。
三种加载程序集的函数
(1)一般用来加载在同一文件下的其它程序集
cs
Assembly asembly2 = Assembly.Load("程序集名称");
(2)一般用来加载不在同一文件下的其它程序集
cs
Assembly asembly = Assembly.LoadFrom("包含程序集清单的文件的名称或路径");
Assembly asembly3 = Assembly.LoadFile("要加载的文件的完全限定路径");
Activator
用于快速实例化对象的类,用于将Type对象快捷实例化为对象,先得到Type,然后 快速实例化一个对象
cs
Type testType = typeof(Test);
//1.无参构造
Test testObj = Activator.CreateInstance(testType) as Test;
Console.WriteLine(testObj.str);
//2.有参数构造
testObj = Activator.CreateInstance(testType, 99) as Test;
Console.WriteLine(testObj.j);
testObj = Activator.CreateInstance(testType, 55, "111222") as Test;
Console.WriteLine(testObj.j);