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 = gcnew 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.
array<Byte>^ temp0 = {01,00,01};
FieldBuilder^ myFieldBuilder =
   myModuleBuilder->DefineInitializedData( "MyField", temp0,
      (FieldAttributes)(FieldAttributes::Static | FieldAttributes::Public) );
myModuleBuilder->CreateGlobalFunctions();
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 呼び出されるまで作成されません。

注意

.NET Framework 2.0 Service Pack 1 以降では、このメンバーは フラグをReflectionPermissionFlag.ReflectionEmit使用する必要ReflectionPermissionがなくなりました。 (リフレクション出力のセキュリティの問題に関するページを参照してください)。この機能を使用するには、アプリケーションで .NET Framework 3.5 以降をターゲットにする必要があります。

適用対象