다음을 통해 공유


ModuleBuilder.DefineInitializedData 메서드

PE 파일(이식 가능한 실행 파일)의 .sdata 섹션에서 초기화된 데이터 필드를 정의합니다.

네임스페이스: System.Reflection.Emit
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Function DefineInitializedData ( _
    name As String, _
    data As Byte(), _
    attributes As FieldAttributes _
) As FieldBuilder
‘사용 방법
Dim instance As ModuleBuilder
Dim name As String
Dim data As Byte()
Dim attributes As FieldAttributes
Dim returnValue As FieldBuilder

returnValue = instance.DefineInitializedData(name, data, attributes)
public FieldBuilder DefineInitializedData (
    string name,
    byte[] data,
    FieldAttributes attributes
)
public:
FieldBuilder^ DefineInitializedData (
    String^ name, 
    array<unsigned char>^ data, 
    FieldAttributes attributes
)
public FieldBuilder DefineInitializedData (
    String name, 
    byte[] data, 
    FieldAttributes attributes
)
public function DefineInitializedData (
    name : String, 
    data : byte[], 
    attributes : FieldAttributes
) : FieldBuilder

매개 변수

  • name
    데이터를 참조하는 데 사용되는 이름입니다. name은 null을 포함할 수 없습니다.
  • data
    데이터의 BLOB입니다.
  • attributes
    필드의 특성입니다. 기본값은 Static입니다.

반환 값

데이터를 참조하는 필드입니다.

예외

예외 형식 조건

ArgumentException

name의 길이가 0인 경우

- 또는 -

data의 크기가 0보다 작거나 같은 경우이거나, 0x3f0000보다 크거나 같은 경우

ArgumentNullException

name 또는 data가 Null 참조(Visual Basic의 경우 Nothing)인 경우

InvalidOperationException

CreateGlobalFunctions을 이미 호출한 경우

설명

Static은 attributes에 자동으로 포함됩니다.

이 메서드로 정의된 데이터는 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()
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();
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.get_CurrentDomain();

myAssemblyName = new AssemblyName();
myAssemblyName.set_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 ubyte[] { 1, 0, 1 }, 
    FieldAttributes.Static | FieldAttributes.Public);
myModuleBuilder.CreateGlobalFunctions();

.NET Framework 보안

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

ModuleBuilder 클래스
ModuleBuilder 멤버
System.Reflection.Emit 네임스페이스