[C#, CSharp] 編譯單位(Compiler Unit)
編譯單位
- PE(Portable Execute File):程式經編譯器編譯後產生由MSIL及中繼資料(Meta Data)組成的可攜式執行檔
- 特性(Attributes):讓設計者在中繼資料(metadata)中增加資料的機制
- 特性(Attributes)會被加入在中繼資料(metadata)中
- 特性(Attributes)可經由ILDasm或其它中繼資料(metadata)讀取工具來讀取
- 反射(Reflection):程式讀取自己中繼資料(metadata)的機制 如同鏡子反射物體本身形成鏡中影像
- 編譯單位:C#以個別程式檔為編譯單位,一個程式檔即為一個編譯單位
- 編譯單位的格式:
[extern-alias-directives] // Ex: extern alias 識別項 [using-directives] // Ex: using System; // Ex: using sys=System.Console; [global-attributes] // Ex: [assembly: AssemblyVersion("1.0.0.0")] [namespace-member-declarations] // Ex: class 類別 { }
- using-directives會影響同編譯單位內的global-attributes和namespace-member-declarations
- 在編譯單位內宣告型別只能使用存取修飾詞public或internal,若沒指明預設為internal存取
- 編譯單位的格式: