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[])

ソース:
ModuleBuilder.cs
ソース:
ModuleBuilder.cs
ソース:
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 です。

namenullです。

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

次の例は、 を使用して、現在ModuleBuilderDefineGlobalMethod に関連付けられた型に依存しないメソッドを作成する方法を示しています。 グローバル メソッドをビルドした後、それを完了するには、 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 Service Pack 1 以降では、このメンバーは フラグをReflectionPermissionFlag.ReflectionEmit使用する必要ReflectionPermissionがなくなりました。 (リフレクション出力のセキュリティの問題に関するページを参照してください)。この機能を使用するには、アプリケーションで .NET Framework 3.5 以降をターゲットにする必要があります。

適用対象

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

ソース:
ModuleBuilder.cs
ソース:
ModuleBuilder.cs
ソース:
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 です。

namenullです。

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

次のコード サンプルは、 を使用して、現在ModuleBuilderDefineGlobalMethod に関連付けられている型に依存しないメソッドを作成する方法を示しています。 グローバル メソッドをビルドした後、それを完了するには、 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 Service Pack 1 以降では、このメンバーは フラグをReflectionPermissionFlag.ReflectionEmit使用する必要ReflectionPermissionがなくなりました。 (リフレクション出力のセキュリティの問題に関するページを参照してください)。この機能を使用するには、アプリケーションで .NET Framework 3.5 以降をターゲットにする必要があります。

適用対象

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

ソース:
ModuleBuilder.cs
ソース:
ModuleBuilder.cs
ソース:
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[]

IsConstIsBoxed などの、戻り値の型の必須のカスタム修飾子を表す型の配列。 戻り値の型が必須のカスタム修飾子を持たない場合は、null を指定します。

optionalReturnTypeCustomModifiers
Type[]

IsConstIsBoxed などの、戻り値の型のオプションのカスタム修飾子を表す型の配列。 戻り値の型に省略可能のカスタム修飾子がない場合は、null を指定します。

parameterTypes
Type[]

メソッドのパラメーター型。

requiredParameterTypeCustomModifiers
Type[][]

型の配列の配列。 型の各配列は、グローバル メソッドの対応するパラメーターの必須のカスタム修飾子を表します。 特定の引数に必須のカスタム修飾子がない場合は、型の配列の代わりに null を指定します。 グローバル メソッドに引数がない場合、またはどの引数にも必須のカスタム修飾子がない場合は、配列の配列の代わりに null を指定します。

optionalParameterTypeCustomModifiers
Type[][]

型の配列の配列。 型の各配列は、対応するパラメーターのオプションのカスタム修飾子を表します。 特定の引数にオプションのカスタム修飾子がない場合は、型の配列の代わりに null を指定します。 グローバル メソッドに引数がない場合、またはどの引数にもオプションのカスタム修飾子がない場合は、配列の配列の代わりに null を指定します。

戻り値

定義されたグローバル メソッド。

例外

メソッドは静的ではありません。 つまり、attributesStatic が含まれていません。

- または -

Type 配列の要素が null です。

namenullです。

CreateGlobalFunctions() メソッドは既に呼び出されています。

注釈

このオーバーロードは、マネージド コンパイラのデザイナー向けに提供されます。

を呼び出 CreateGlobalFunctionsすまで、このメソッドが定義するグローバル メソッドを使用することはできません。

注意

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

適用対象