ModuleBuilder.DefineGlobalMethod 메서드

정의

전역 메서드를 정의합니다.

오버로드

DefineGlobalMethod(String, MethodAttributes, Type, Type[])

이름, 특성, 반환 형식 및 매개 변수 형식을 지정하여 전역 메서드를 정의합니다.

DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[])

이름, 특성, 호출 규칙, 반환 형식 및 매개 변수 형식을 지정하여 전역 메서드를 정의합니다.

DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

이름, 특성, 호출 규칙, 반환 형식, 반환 형식에 대한 사용자 지정 한정자, 매개 변수 형식 및 매개 변수 형식에 대한 사용자 지정 한정자를 지정하여 전역 메서드를 정의합니다.

DefineGlobalMethod(String, MethodAttributes, Type, Type[])

Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs

이름, 특성, 반환 형식 및 매개 변수 형식을 지정하여 전역 메서드를 정의합니다.

public:
 System::Reflection::Emit::MethodBuilder ^ DefineGlobalMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod (string name, System.Reflection.MethodAttributes attributes, Type? returnType, Type[]? parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod (string name, System.Reflection.MethodAttributes attributes, Type returnType, Type[] parameterTypes);
member this.DefineGlobalMethod : string * System.Reflection.MethodAttributes * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineGlobalMethod (name As String, attributes As MethodAttributes, returnType As Type, parameterTypes As Type()) As MethodBuilder

매개 변수

name
String

메서드의 이름입니다. name에는 내장된 null이 포함될 수 없습니다.

attributes
MethodAttributes

메서드의 특성입니다. attributes에는 Static이 포함되어야 합니다.

returnType
Type

메서드의 반환 형식입니다.

parameterTypes
Type[]

메서드 매개 변수의 형식입니다.

반환

정의된 전역 메서드입니다.

예외

메서드가 정적이 아닙니다. 즉 attributesStatic이 포함되어 있지 않은 경우

또는

name의 길이가 0인 경우

또는

Type 배열의 요소가 null인 경우

name이(가) null인 경우

CreateGlobalFunctions()이 이전에 호출되었습니다.

예제

다음 예제에서는 를 사용하여 DefineGlobalMethod 현재 ModuleBuilder에 연결된 형식 독립적 메서드를 만드는 방법을 보여 줍니다. 전역 메서드 CreateGlobalFunctions 를 빌드한 후에는 를 호출하여 완료해야 합니다.

AppDomain^ currentDomain;
AssemblyName^ myAssemblyName;
MethodBuilder^ myMethodBuilder = nullptr;
ILGenerator^ myILGenerator;

// 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::RunAndSave );

// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder->DefineGlobalMethod(
   "MyMethod1", (MethodAttributes)(MethodAttributes::Static | MethodAttributes::Public),
   nullptr, nullptr );
myILGenerator = myMethodBuilder->GetILGenerator();
myILGenerator->EmitWriteLine( "Hello World from global method." );
myILGenerator->Emit( OpCodes::Ret );

// Fix up the 'TempModule' module .
myModuleBuilder->CreateGlobalFunctions();
AppDomain currentDomain;
AssemblyName myAssemblyName;
MethodBuilder myMethodBuilder=null;
ILGenerator myILGenerator;

// 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.RunAndSave);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod
     ("MyMethod1",MethodAttributes.Static|MethodAttributes.Public,
           null,null);
myILGenerator = myMethodBuilder.GetILGenerator();
myILGenerator.EmitWriteLine("Hello World from global method.");
myILGenerator.Emit(OpCodes.Ret);
// Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions();
Dim currentDomain As AppDomain
Dim myAssemblyName As AssemblyName
Dim myMethodBuilder As MethodBuilder = Nothing
Dim myILGenerator As ILGenerator

' 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.RunAndSave)
' Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")

' Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod("MyMethod1", MethodAttributes.Static _
                                          Or MethodAttributes.Public, Nothing, Nothing)
myILGenerator = myMethodBuilder.GetILGenerator()
myILGenerator.EmitWriteLine("Hello World from global method.")
myILGenerator.Emit(OpCodes.Ret)
' Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions()

설명

이 메서드가 정의하는 전역 메서드는 를 호출 CreateGlobalFunctions할 때까지 사용할 수 없습니다.

참고

.NET Framework 2.0 서비스 팩 1부터 이 멤버는 ReflectionPermission 더 이상 플래그를 ReflectionPermissionFlag.ReflectionEmit 사용할 필요가 없습니다. (리플렉션 내보내기의 보안 문제를 참조하세요.) 이 기능을 사용하려면 애플리케이션이 .NET Framework 3.5 이상을 대상으로 해야 합니다.

적용 대상

DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[])

Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs

이름, 특성, 호출 규칙, 반환 형식 및 매개 변수 형식을 지정하여 전역 메서드를 정의합니다.

public:
 System::Reflection::Emit::MethodBuilder ^ DefineGlobalMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes);
member this.DefineGlobalMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineGlobalMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type()) As MethodBuilder

매개 변수

name
String

메서드의 이름입니다. name에는 내장된 null이 포함될 수 없습니다.

attributes
MethodAttributes

메서드의 특성입니다. attributes에는 Static이 포함되어야 합니다.

callingConvention
CallingConventions

메서드의 호출 규칙입니다.

returnType
Type

메서드의 반환 형식입니다.

parameterTypes
Type[]

메서드 매개 변수의 형식입니다.

반환

정의된 전역 메서드입니다.

예외

메서드가 정적이 아닙니다. 즉 attributesStatic이 포함되어 있지 않은 경우

또는

Type 배열의 요소가 null인 경우

name이(가) null인 경우

CreateGlobalFunctions()이 이전에 호출되었습니다.

예제

다음 코드 샘플에서는 를 사용하여 DefineGlobalMethod 현재 ModuleBuilder에 연결된 형식 독립적 메서드를 만드는 방법을 보여 줍니다. 전역 메서드 CreateGlobalFunctions 를 빌드한 후에는 를 호출하여 완료해야 합니다.

AppDomain^ currentDomain;
AssemblyName^ myAssemblyName;
MethodBuilder^ myMethodBuilder = nullptr;
ILGenerator^ myILGenerator;

// 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::RunAndSave );

// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder->DefineGlobalMethod(
   "MyMethod1", (MethodAttributes)(MethodAttributes::Static | MethodAttributes::Public),
   nullptr, nullptr );
myILGenerator = myMethodBuilder->GetILGenerator();
myILGenerator->EmitWriteLine( "Hello World from global method." );
myILGenerator->Emit( OpCodes::Ret );

// Fix up the 'TempModule' module .
myModuleBuilder->CreateGlobalFunctions();
AppDomain currentDomain;
AssemblyName myAssemblyName;
MethodBuilder myMethodBuilder=null;
ILGenerator myILGenerator;

// 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.RunAndSave);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod
     ("MyMethod1",MethodAttributes.Static|MethodAttributes.Public,
           null,null);
myILGenerator = myMethodBuilder.GetILGenerator();
myILGenerator.EmitWriteLine("Hello World from global method.");
myILGenerator.Emit(OpCodes.Ret);
// Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions();
Dim currentDomain As AppDomain
Dim myAssemblyName As AssemblyName
Dim myMethodBuilder As MethodBuilder = Nothing
Dim myILGenerator As ILGenerator

' 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.RunAndSave)
' Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")

' Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod("MyMethod1", MethodAttributes.Static _
                                          Or MethodAttributes.Public, Nothing, Nothing)
myILGenerator = myMethodBuilder.GetILGenerator()
myILGenerator.EmitWriteLine("Hello World from global method.")
myILGenerator.Emit(OpCodes.Ret)
' Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions()

설명

를 호출 CreateGlobalFunctions할 때까지 이 메서드가 정의하는 전역 메서드를 사용할 수 없습니다.

참고

.NET Framework 2.0 서비스 팩 1부터 이 멤버는 ReflectionPermission 더 이상 플래그를 ReflectionPermissionFlag.ReflectionEmit 사용할 필요가 없습니다. (리플렉션 내보내기의 보안 문제를 참조하세요.) 이 기능을 사용하려면 애플리케이션이 .NET Framework 3.5 이상을 대상으로 해야 합니다.

적용 대상

DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs

이름, 특성, 호출 규칙, 반환 형식, 반환 형식에 대한 사용자 지정 한정자, 매개 변수 형식 및 매개 변수 형식에 대한 사용자 지정 한정자를 지정하여 전역 메서드를 정의합니다.

public:
 System::Reflection::Emit::MethodBuilder ^ DefineGlobalMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ requiredReturnTypeCustomModifiers, cli::array <Type ^> ^ optionalReturnTypeCustomModifiers, cli::array <Type ^> ^ parameterTypes, cli::array <cli::array <Type ^> ^> ^ requiredParameterTypeCustomModifiers, cli::array <cli::array <Type ^> ^> ^ optionalParameterTypeCustomModifiers);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? requiredReturnTypeCustomModifiers, Type[]? optionalReturnTypeCustomModifiers, Type[]? parameterTypes, Type[][]? requiredParameterTypeCustomModifiers, Type[][]? optionalParameterTypeCustomModifiers);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers);
member this.DefineGlobalMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * Type[] * Type[] * Type[][] * Type[][] -> System.Reflection.Emit.MethodBuilder
Public Function DefineGlobalMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, requiredReturnTypeCustomModifiers As Type(), optionalReturnTypeCustomModifiers As Type(), parameterTypes As Type(), requiredParameterTypeCustomModifiers As Type()(), optionalParameterTypeCustomModifiers As Type()()) As MethodBuilder

매개 변수

name
String

메서드의 이름입니다. name은 null 문자를 포함할 수 없습니다.

attributes
MethodAttributes

메서드의 특성입니다. attributes에는 Static이 포함되어야 합니다.

callingConvention
CallingConventions

메서드의 호출 규칙입니다.

returnType
Type

메서드의 반환 형식입니다.

requiredReturnTypeCustomModifiers
Type[]

IsConst 또는 IsBoxed와 같이 반환 형식에 대한 필수적 사용자 지정 한정자를 나타내는 형식의 배열입니다. 반환 형식에 필수 사용자 지정 한정자가 없으면 null을 지정합니다.

optionalReturnTypeCustomModifiers
Type[]

IsConst 또는 IsBoxed와 같이 반환 형식에 대한 선택적 사용자 지정 한정자를 나타내는 형식의 배열입니다. 반환 형식에 선택적 사용자 지정 한정자가 없으면 null을 지정합니다.

parameterTypes
Type[]

메서드 매개 변수의 형식입니다.

requiredParameterTypeCustomModifiers
Type[][]

형식 배열의 배열입니다. 각 형식 배열은 전역 메서드의 해당 매개 변수에 대한 필수적 사용자 지정 한정자를 나타냅니다. 특정 인수에 필수적 사용자 지정 한정자가 없는 경우에는 형식 배열 대신 null을 지정합니다. 전역 메서드에 인수가 없거나 모든 인수에 필수적 사용자 지정 한정자가 없는 경우에는 배열로 이루어진 배열 대신 null을 지정합니다.

optionalParameterTypeCustomModifiers
Type[][]

형식 배열의 배열입니다. 각 형식 배열은 해당 매개 변수에 대한 선택적 사용자 지정 한정자를 나타냅니다. 특정 인수에 선택적 사용자 지정 한정자가 없는 경우에는 형식 배열 대신 null을 지정합니다. 전역 메서드에 인수가 없거나 모든 인수에 선택적 사용자 지정 한정자가 없는 경우에는 배열로 이루어진 배열 대신 null을 지정합니다.

반환

정의된 전역 메서드입니다.

예외

메서드가 정적이 아닙니다. 즉 attributesStatic이 포함되어 있지 않은 경우

또는

Type 배열의 요소가 null인 경우

name이(가) null인 경우

CreateGlobalFunctions() 메서드가 이미 호출된 경우

설명

이 오버로드는 관리되는 컴파일러의 디자이너에 대해 제공됩니다.

를 호출 CreateGlobalFunctions할 때까지 이 메서드가 정의하는 전역 메서드를 사용할 수 없습니다.

참고

.NET Framework 2.0 서비스 팩 1부터 이 멤버는 ReflectionPermission 더 이상 플래그를 ReflectionPermissionFlag.ReflectionEmit 사용할 필요가 없습니다. (리플렉션 내보내기의 보안 문제를 참조하세요.) 이 기능을 사용하려면 애플리케이션이 .NET Framework 3.5 이상을 대상으로 해야 합니다.

적용 대상