ModuleBuilder.DefineGlobalMethod メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
グローバル メソッドを定義します。
オーバーロード
| 名前 | 説明 |
|---|---|
| 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[])
指定した名前、属性、戻り値の型、およびパラメーター型を持つグローバル メソッドを定義します。
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);
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[]
メソッドのパラメーターの型。
返品
定義されたグローバル メソッド。
例外
name は nullです。
CreateGlobalFunctions() は以前に呼び出されています。
例
次の例は、 DefineGlobalMethod を使用して、現在の ModuleBuilderに関連付けられた型に依存しないメソッドを作成する方法を示しています。 グローバル メソッドをビルドした後、 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を呼び出すまで使用できません。
適用対象
DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[])
指定した名前、属性、呼び出し規則、戻り値の型、およびパラメーター型を持つグローバル メソッドを定義します。
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);
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[]
メソッドのパラメーターの型。
返品
定義されたグローバル メソッド。
例外
name は nullです。
CreateGlobalFunctions() は以前に呼び出されています。
例
次のコード サンプルは、 DefineGlobalMethod を使用して、現在の ModuleBuilderに関連付けられた型に依存しないメソッドを作成する方法を示しています。 グローバル メソッドをビルドした後、 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を呼び出すまで使用できません。
適用対象
DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])
指定した名前、属性、呼び出し規則、戻り値の型、戻り値の型のカスタム修飾子、パラメーター型、およびパラメーター型のカスタム修飾子を持つグローバル メソッドを定義します。
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);
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 を指定します。
返品
定義されたグローバル メソッド。
例外
name は nullです。
CreateGlobalFunctions() メソッドは以前に呼び出されています。
注釈
このオーバーロードは、マネージド コンパイラのデザイナーに提供されます。
このメソッドが定義するグローバル メソッドは、 CreateGlobalFunctionsを呼び出すまで使用できません。