ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) Method

定義

移植可能な実行可能 (PE) ファイルの .sdata セクションに、初期化済みデータ フィールドを定義します。Defines an initialized data field in the .sdata section of the portable executable (PE) file.

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 String String String

データを参照するために使用する名前。The name used to refer to the data. name に埋め込み null 値を含めることはできません。name cannot contain embedded nulls.

data
Byte[]

データのバイナリ ラージ オブジェクト (BLOB)。The binary large object (BLOB) of data.

attributes
FieldAttributes FieldAttributes FieldAttributes FieldAttributes

フィールドの属性。The attributes for the field. 既定値は、Static です。The default is Static.

戻り値

データを参照するフィールド。A field to reference the data.

例外

name の長さが 0 です。The length of name is zero.

- または --or- data のサイズが 0 以下か、0x3f0000 以上です。The size of data is less than or equal to zero or greater than or equal to 0x3f0000.

name または datanull です。name or data is null.

次の例ではDefineInitializedData 、メソッドを使用して、ポータブル実行.sdata可能 (PE) ファイルのセクションに初期化されたデータフィールドを定義しています。The following example uses the DefineInitializedData method to define an initialized data field in the .sdata section of the portable executable (PE) file.

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に自動的に含まれます。Static is automatically included in attributes.

このメソッドによって定義されるデータは、 CreateGlobalFunctionsメソッドが呼び出されるまで作成されません。The data defined by this method is not created until the CreateGlobalFunctions method is called.

注意

以降では.NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1、このメンバーはフラグをReflectionPermission使用するReflectionPermissionFlag.ReflectionEmit必要がなくなりました。Starting with the .NET Framework 2.0 Service Pack 1.NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (「リフレクション出力のセキュリティの問題」を参照してください)。この機能を使用するには、アプリケーションで .NET Framework 3.5.NET Framework 3.5 以降を対象とする必要があります。(See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5.NET Framework 3.5 or later.

適用対象