ModuleBuilder.DefineGlobalMethod Método

Definición

Define un método global.

Sobrecargas

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

Define un método global con el nombre, los atributos, la convención de llamada, el tipo de valor devuelto y los tipos de parámetro especificados.

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

Define un método global con el nombre, los atributos, la convención de llamada, el tipo de valor devuelto, los modificadores personalizados para el tipo de valor devuelto, los tipos de parámetro y los modificadores personalizados para los tipos de parámetro.

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

Define un método global con el nombre, los atributos, el tipo de valor devuelto y los tipos de parámetro especificados.

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

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

Define un método global con el nombre, los atributos, la convención de llamada, el tipo de valor devuelto y los tipos de parámetro especificados.

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

Parámetros

name
String

Nombre del método. name no puede contener valores NULL incrustados.

attributes
MethodAttributes

Atributos del método . attributes debe incluir Static.

callingConvention
CallingConventions

La convención de llamada para el método .

returnType
Type

Tipo de valor devuelto del método .

parameterTypes
Type[]

Los tipos de los parámetros del método.

Devoluciones

Método global definido.

Excepciones

El método no es estático. Es decir, attributes no incluye Static.

O bien

Un elemento de la Type matriz es null.

name es null.

CreateGlobalFunctions() se ha llamado anteriormente.

Ejemplos

En el ejemplo de código siguiente se muestra el uso de DefineGlobalMethod para crear un método independiente del tipo asociado al objeto actual ModuleBuilder. Después de compilar el método global, CreateGlobalFunctions se debe llamar a para completarlo.

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()

Comentarios

No puede usar el método global que define este método hasta que llame a CreateGlobalFunctions.

Se aplica a

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

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

Define un método global con el nombre, los atributos, la convención de llamada, el tipo de valor devuelto, los modificadores personalizados para el tipo de valor devuelto, los tipos de parámetro y los modificadores personalizados para los tipos de parámetro.

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

Parámetros

name
String

Nombre del método. name no puede contener caracteres NULL incrustados.

attributes
MethodAttributes

Atributos del método . attributes debe incluir Static.

callingConvention
CallingConventions

La convención de llamada para el método .

returnType
Type

Tipo de valor devuelto del método .

requiredReturnTypeCustomModifiers
Type[]

Matriz de tipos que representan los modificadores personalizados necesarios para el tipo de valor devuelto, como IsConst o IsBoxed. Si el tipo de valor devuelto no tiene modificadores personalizados necesarios, especifique null.

optionalReturnTypeCustomModifiers
Type[]

Matriz de tipos que representan los modificadores personalizados opcionales para el tipo de valor devuelto, como IsConst o IsBoxed. Si el tipo de valor devuelto no tiene modificadores personalizados opcionales, especifique null.

parameterTypes
Type[]

Los tipos de los parámetros del método.

requiredParameterTypeCustomModifiers
Type[][]

Matriz de matrices de tipos. Cada matriz de tipos representa los modificadores personalizados necesarios para el parámetro correspondiente del método global. Si un argumento determinado no tiene modificadores personalizados necesarios, especifique null en lugar de una matriz de tipos. Si el método global no tiene argumentos o si ninguno de los argumentos tiene modificadores personalizados necesarios, especifique null en lugar de una matriz de matrices.

optionalParameterTypeCustomModifiers
Type[][]

Matriz de matrices de tipos. Cada matriz de tipos representa los modificadores personalizados opcionales para el parámetro correspondiente. Si un argumento determinado no tiene modificadores personalizados opcionales, especifique null en lugar de una matriz de tipos. Si el método global no tiene argumentos o si ninguno de los argumentos tiene modificadores personalizados opcionales, especifique null en lugar de una matriz de matrices.

Devoluciones

Método global definido.

Excepciones

El método no es estático. Es decir, attributes no incluye Static.

O bien

Un elemento de la Type matriz es null.

name es null.

Se CreateGlobalFunctions() ha llamado previamente al método .

Comentarios

Esta sobrecarga se proporciona para diseñadores de compiladores administrados.

No puede usar el método global que define este método hasta que llame a CreateGlobalFunctions.

Se aplica a

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

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

Define un método global con el nombre, los atributos, el tipo de valor devuelto y los tipos de parámetro especificados.

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

Parámetros

name
String

Nombre del método. name no puede contener valores NULL incrustados.

attributes
MethodAttributes

Atributos del método . attributes debe incluir Static.

returnType
Type

Tipo de valor devuelto del método .

parameterTypes
Type[]

Los tipos de los parámetros del método.

Devoluciones

Método global definido.

Excepciones

El método no es estático. Es decir, attributes no incluye Static.

O bien

La longitud de name es cero

O bien

Un elemento de la Type matriz es null.

name es null.

CreateGlobalFunctions() se ha llamado anteriormente.

Ejemplos

En el ejemplo siguiente se muestra el uso de DefineGlobalMethod para crear un método independiente del tipo asociado al objeto actual ModuleBuilder. Después de compilar el método global, CreateGlobalFunctions se debe llamar a para completarlo.

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()

Comentarios

El método global que define este método no se puede usar hasta que llame a CreateGlobalFunctions.

Se aplica a