C#反射(System.Reflection )
[@more@]
C# System.Reflection 反射
反射的概述 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射appDomain <wbr>的程式集 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射單個程式集 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>利用反射獲取型別資訊 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>設定反射型別的成員 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>透過反射建立型別的例項 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射型別的介面 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射的效能 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射的概述 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> 反射的定義:審查後設資料並收集關於它的型別資訊的能力。後設資料(編譯以後的最基本資料單元)就是一大堆的表,當編譯程式集或者模組時,編譯器會建立一個類定義表,一個欄位定義表,和一個方法定義表等,。System.reflection名稱空間包含的幾個類,允許你反射(解析)這些後設資料表的程式碼 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>和反射相關的名稱空間(我們就是透過這幾個名稱空間訪問反射資訊): <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>System.Reflection.MemberInfo <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Reflection.EventInfo <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Reflection.FieldInfo <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Reflection.MethodBase <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Reflection.ConstructorInfo <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Reflection.MethodInfo <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Reflection.PropertyInfo <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Type <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>System.Reflection.Assembly <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射的層次模型: <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>注:層次間都是一對多的關係 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射的作用: <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>1. <wbr>可以使用反射動態地建立型別的例項,將型別繫結到現有物件,或從現 <wbr>有物件中獲取型別 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>2. <wbr>應用程式需要在執行時從某個特定的程式集中載入一個特定的型別,以便實現某個任務時可以用到反射。 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>3. <wbr>反射主要應用與類庫,這些類庫需要知道一個型別的定義,以便提供更多的功能。 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>應用要點: <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>1. <wbr>現實應用程式中很少有應用程式需要使用反射型別 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>2. <wbr>使用反射動態繫結需要犧牲效能 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>3. <wbr>有些後設資料資訊是不能透過反射獲取的 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>4. <wbr>某些反射型別是專門為那些clr <wbr>開發編譯器的開發使用的,所以你要意識到不是所有的反射型別都是適合每個人的。 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr>反射appDomain <wbr>的程式集 <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>當你需要反射AppDomain <wbr>中包含的所有程式集,示例如下: <wbr>
<wbr> <wbr> <wbr>static <wbr>void <wbr>Main <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>{ <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>//透過GetAssemblies <wbr>呼叫appDomain的所有程式集 <wbr>
<wbr>