ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) メソッド

定義

ポータブル実行可能ファイル (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 埋め込み null を含めることはできません。

data
Byte[]

データのバイナリ ラージ オブジェクト (BLOB)。

attributes
FieldAttributes

フィールドの属性。 既定値は Static です。

返品

データを参照するフィールド。

例外

nameの長さは 0 です。

-または-

dataのサイズが 0 以下か、0x3f0000以上です。

name または datanull

CreateGlobalFunctions() は以前に呼び出されています。

次の例では、 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 メソッドが呼び出されるまで作成されません。

適用対象