C# Assembly类访问程序集信息

来源:这里教程网 时间:2026-02-21 13:04:02 作者:

c#中通过assembly类可以访问程序集信息. 
1.允许访问给定程序集的元元素,包含可以加载和执行程序集的方法; 
2.加载程序集:使用静态方法assembly.load(程序集名称)或assembly.loadfrom(程序集完整路径名); 
3.属性: 
fullname:程序集显示名称; 
3.方法: 
gettypes():获取程序集中定义的类型。 
testassembly.cs: 
view plaincopy to clipboardprint? 
using system; using system.reflection; 
namespace magci.test.reflection 
{ public class testassembly 
{ public static void main() 
{ //将程序集加载到运行过程中 
assembly ass = assembly.load("testcustomattributes"); 
assembly ass1 = assembly.loadfrom(@"e:\code\dotnet\c#\9-reflection\testcustomattributes.dll"); 
//获取程序集显示名称 
console.writeline(ass1.fullname); 
//获取程序集中定义的类型 
type[] types = ass.gettypes(); 
foreach (type t in types) 
{ console.writeline(t.fullname); 
} } } }

以上就是C# Assembly类访问程序集信息的内容,更多相关文章请关注PHP中文网(www.php.cn)!

相关推荐