程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> C# Assembly類訪問程序集信息

C# Assembly類訪問程序集信息

編輯:關於PHP編程

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);
} } } }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved