主站  鏡像       简体版 繁體版 English  
  
 
rouse studio  黯然奮發C#C#中通過Assembly類訪問程序集信息
C#中通过Assembly类访问程序集信息
文 / 佚名   來源於:互聯網

C#中通過Assembly類可以訪問程序集信息。

 

1.允許訪問給定程序集的元元素,包含可以加載和執行程序集的方法;

 

2.加載程序集:

    使用靜態方法Assembly.Load(程序集名稱)Assembly.LoadFrom(程序集完整路徑名);

 

3.屬性:

    FullName:程序集顯示名稱;

 

4.方法:

    GetTypes():獲取程序集中定義的類型。

 

TestAssembly.cs:

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

            }

        }

    } 

meteor   上傳於[7/20/2010 10:41:17 PM] | 點擊15次 | 評論0條 | 查看評論 | 【返回頁首】  
相關文章
黯然奮發
Copyright © 2004-2010 rouse studio All Rights Reserved.
奮發工作室 版權所有 嚴禁轉載
Powered by rouse cms 2.3 © 2009-2010 rouse studio.