ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在可攜式可執行檔(PE)檔案的 .sdata 區段定義已初始化的資料欄位。
public:
System::Reflection::Emit::FieldBuilder ^ DefineInitializedData(System::String ^ name, cli::array <System::Byte> ^ data, System::Reflection::FieldAttributes attributes);
public System.Reflection.Emit.FieldBuilder DefineInitializedData(string name, byte[] data, System.Reflection.FieldAttributes attributes);
member this.DefineInitializedData : string * byte[] * System.Reflection.FieldAttributes -> System.Reflection.Emit.FieldBuilder
Public Function DefineInitializedData (name As String, data As Byte(), attributes As FieldAttributes) As FieldBuilder
參數
- name
- String
這個名稱過去用來指稱這些資料。
name 無法包含嵌入的空。
- data
- Byte[]
資料的二進位大型物件(BLOB)。
- attributes
- FieldAttributes
該領域的屬性。 預設值為 Static。
傳回
一個用來參考資料的欄位。
例外狀況
name 或 data 為 null。
範例
以下範例使用此 DefineInitializedData 方法,在可攜式可執行檔(PE)的區段中定義初始化的資料欄位 .sdata 。
AppDomain currentDomain;
AssemblyName myAssemblyName;
// Get the current application domain for the current thread.
currentDomain = AppDomain.CurrentDomain;
myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder =
currentDomain.DefineDynamicAssembly
(myAssemblyName, AssemblyBuilderAccess.Run);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");
// Define the initialized data field in the .sdata section of the PE file.
FieldBuilder myFieldBuilder =
myModuleBuilder.DefineInitializedData("MyField",new byte[]{01,00,01},
FieldAttributes.Static|FieldAttributes.Public);
myModuleBuilder.CreateGlobalFunctions();
Dim currentDomain As AppDomain
Dim myAssemblyName As AssemblyName
' Get the current application domain for the current thread.
currentDomain = AppDomain.CurrentDomain
myAssemblyName = New AssemblyName()
myAssemblyName.Name = "TempAssembly"
' Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder = _
currentDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
' Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")
' Define the initialized data field in the .sdata section of the PE file.
Dim myFieldBuilder As FieldBuilder = _
myModuleBuilder.DefineInitializedData("MyField", New Byte() {1, 0, 1}, _
FieldAttributes.Static Or FieldAttributes.Public)
myModuleBuilder.CreateGlobalFunctions()
備註
Static 自動包含在 attributes。
此方法定義的資料直到 CreateGlobalFunctions 方法被呼叫時才會被建立。