ModuleBuilder.DefineGlobalMethod Método

Definição

Define um método global.

Sobrecargas

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

Define um método global com o nome especificado, atributos, tipo de retorno e tipos de parâmetros.

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

Define um método global com o nome especificado, atributos, convenção de chamada, tipo de retorno e tipos de parâmetro.

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

Define um método global com o nome especificado, atributos, convenção de chamada, tipo de retorno, modificadores personalizados para o tipo de retorno, tipos de parâmetros e modificadores personalizados para os tipos de parâmetro.

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

Define um método global com o nome especificado, atributos, tipo de retorno e tipos de parâmetros.

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

Parâmetros

name
String

O nome do método. name não pode conter nulos embutidos.

attributes
MethodAttributes

Os atributos do método. attributes deve incluir Static.

returnType
Type

O tipo de retorno do método.

parameterTypes
Type[]

Os tipos de parâmetros do método.

Devoluções

O método global definido.

Exceções

O método não é estático. Ou seja, attributes não inclui Static.

-ou-

O comprimento de name é zero

-ou-

Um elemento no Type array é null.

name é null.

CreateGlobalFunctions() já foi anteriormente chamado.

Exemplos

O exemplo seguinte ilustra o uso de DefineGlobalMethod para criar um método independente de tipo ligado ao atual ModuleBuilder. Depois de construir o método global, CreateGlobalFunctions deve ser chamado para o completar.

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

Observações

O método global que este método define não é utilizável até que se chame CreateGlobalFunctions.

Aplica-se a

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

Define um método global com o nome especificado, atributos, convenção de chamada, tipo de retorno e 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 ^> ^ 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

O nome do método. name não pode conter nulos embutidos.

attributes
MethodAttributes

Os atributos do método. attributes deve incluir Static.

callingConvention
CallingConventions

A convenção de chamada para o método.

returnType
Type

O tipo de retorno do método.

parameterTypes
Type[]

Os tipos de parâmetros do método.

Devoluções

O método global definido.

Exceções

O método não é estático. Ou seja, attributes não inclui Static.

-ou-

Um elemento no Type array é null.

name é null.

CreateGlobalFunctions() já foi anteriormente chamado.

Exemplos

O exemplo de código seguinte ilustra a utilização de DefineGlobalMethod para criar um método independente de tipo ligado ao atual ModuleBuilder. Depois de construir o método global, CreateGlobalFunctions deve ser chamado para o completar.

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

Observações

Não pode usar o método global que este método define até chamar CreateGlobalFunctions.

Aplica-se a

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

Define um método global com o nome especificado, atributos, convenção de chamada, tipo de retorno, modificadores personalizados para o tipo de retorno, tipos de parâmetros e modificadores personalizados para os 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);
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

O nome do método. name não pode conter caracteres nulos embutidos.

attributes
MethodAttributes

Os atributos do método. attributes deve incluir Static.

callingConvention
CallingConventions

A convenção de chamada para o método.

returnType
Type

O tipo de retorno do método.

requiredReturnTypeCustomModifiers
Type[]

Um array de tipos que representam os modificadores personalizados necessários para o tipo de retorno, como IsConst ou IsBoxed. Se o tipo de retorno não tiver modificadores personalizados obrigatórios, especifique null.

optionalReturnTypeCustomModifiers
Type[]

Um array de tipos que representam os modificadores personalizados opcionais para o tipo de retorno, como IsConst ou IsBoxed. Se o tipo de retorno não tiver modificadores personalizados opcionais, especifique null.

parameterTypes
Type[]

Os tipos de parâmetros do método.

requiredParameterTypeCustomModifiers
Type[][]

Uma variedade de arrays de tipos. Cada array de tipos representa os modificadores personalizados necessários para o parâmetro correspondente do método global. Se um determinado argumento não tiver modificadores personalizados obrigatórios, especifique null em vez de um array de tipos. Se o método global não tiver argumentos, ou se nenhum dos argumentos tiver requerido modificadores personalizados, especifique null em vez de um array de arrays.

optionalParameterTypeCustomModifiers
Type[][]

Uma variedade de arrays de tipos. Cada array de tipos representa os modificadores personalizados opcionais para o parâmetro correspondente. Se um determinado argumento não tiver modificadores personalizados opcionais, especifique null em vez de um array de tipos. Se o método global não tiver argumentos, ou se nenhum dos argumentos tiver modificadores personalizados opcionais, especifique null em vez de um array de arrays.

Devoluções

O método global definido.

Exceções

O método não é estático. Ou seja, attributes não inclui Static.

-ou-

Um elemento no Type array é null.

name é null.

O CreateGlobalFunctions() método já foi referido anteriormente.

Observações

Esta sobrecarga é fornecida para os projetistas de compiladores geridos.

Não pode usar o método global que este método define até chamar CreateGlobalFunctions.

Aplica-se a