ModuleBuilder.DefineGlobalMethod Método

Definição

Define um método global.

Sobrecargas

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

Define um método global com o nome, os atributos, o tipo de retorno e os tipos de parâmetro especificados.

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

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

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

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

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

Origem:
ModuleBuilder.cs
Origem:
ModuleBuilder.cs
Origem:
ModuleBuilder.cs

Define um método global com o nome, os atributos, o tipo de retorno e os 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

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

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.

Retornos

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 na matriz Type é null.

name é null.

Exemplos

O exemplo a seguir ilustra o uso de DefineGlobalMethod para criar um método independente de tipo vinculado ao atual ModuleBuilder. Depois de criar o método global, CreateGlobalFunctions deve ser chamado para concluí-lo.

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

Comentários

O método global que esse método define não é utilizável até que você chame CreateGlobalFunctions.

Observação

A partir do .NET Framework 2.0 Service Pack 1, esse membro não requer ReflectionPermission mais com o ReflectionPermissionFlag.ReflectionEmit sinalizador . (Consulte Problemas de segurança na emissão de reflexão.) Para usar essa funcionalidade, seu aplicativo deve ter como destino o .NET Framework 3.5 ou posterior.

Aplica-se a

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

Origem:
ModuleBuilder.cs
Origem:
ModuleBuilder.cs
Origem:
ModuleBuilder.cs

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

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

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.

Retornos

O método global definido.

Exceções

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

- ou -

Um elemento na matriz Type é null.

name é null.

Exemplos

O exemplo de código a seguir ilustra o uso de DefineGlobalMethod para criar um método independente de tipo vinculado ao atual ModuleBuilder. Depois de criar o método global, CreateGlobalFunctions deve ser chamado para concluí-lo.

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

Comentários

Você não pode usar o método global que esse método define até que você chame CreateGlobalFunctions.

Observação

A partir do .NET Framework 2.0 Service Pack 1, esse membro não requer ReflectionPermission mais com o ReflectionPermissionFlag.ReflectionEmit sinalizador . (Consulte Problemas de segurança na emissão de reflexão.) Para usar essa funcionalidade, seu aplicativo deve ter como destino o .NET Framework 3.5 ou posterior.

Aplica-se a

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

Origem:
ModuleBuilder.cs
Origem:
ModuleBuilder.cs
Origem:
ModuleBuilder.cs

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

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

Uma matriz de tipos que representa os modificadores personalizados obrigató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[]

Uma matriz de tipos que representa 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 matriz de matrizes de tipos. Cada matriz de tipos representa os modificadores personalizados necessários para o parâmetro correspondente do método global. Se um argumento específico não tiver nenhum modificador personalizado obrigatório, especifique null, em vez de uma matriz de tipos. Se o método global não tiver nenhum argumento ou se nenhum argumento tiver modificadores personalizados obrigatórios, especifique null, em vez de uma matriz de matrizes.

optionalParameterTypeCustomModifiers
Type[][]

Uma matriz de matrizes de tipos. Cada matriz de tipos representa os modificadores personalizados opcionais para o parâmetro correspondente. Se um argumento específico não tiver nenhum modificador personalizado opcional, especifique null, em vez de uma matriz de tipos. Se o método global não tiver nenhum argumento ou se nenhum argumento tiver modificadores personalizados opcionais, especifique null, em vez de uma matriz de matrizes.

Retornos

O método global definido.

Exceções

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

- ou -

Um elemento na matriz Type é null.

name é null.

O método CreateGlobalFunctions() foi chamado anteriormente.

Comentários

Essa sobrecarga é fornecida para designers de compiladores gerenciados.

Você não pode usar o método global que esse método define até que você chame CreateGlobalFunctions.

Observação

A partir do .NET Framework 2.0 Service Pack 1, esse membro não requer ReflectionPermission mais com o ReflectionPermissionFlag.ReflectionEmit sinalizador . (Consulte Problemas de segurança na emissão de reflexão.) Para usar essa funcionalidade, seu aplicativo deve ter como destino o .NET Framework 3.5 ou posterior.

Aplica-se a