ModuleBuilder.DefineGlobalMethod Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Define um método global.
Sobrecargas
| Nome | Description |
|---|---|
| DefineGlobalMethod(String, MethodAttributes, Type, Type[]) |
Define um método global com o nome, atributos, tipo de retorno e tipos de parâmetro especificados. |
| DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[]) |
Define um método global com o nome, atributos, convenção de chamada, tipo de retorno e tipos de parâmetro especificados. |
| DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][]) |
Define um método global com o 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[])
Define um método global com o nome, atributos, tipo de retorno e 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);
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 Type matriz é null.
name é null.
CreateGlobalFunctions() foi chamado anteriormente.
Exemplos
O exemplo a seguir ilustra o uso de DefineGlobalMethod um método independente de tipo vinculado ao atual ModuleBuilder. Depois de compilar o método global, CreateGlobalFunctions deve ser chamado para concluí-lo.
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.
Aplica-se a
DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[])
Define um método global com o nome, atributos, convenção de chamada, tipo de retorno e 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);
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 Type matriz é null.
name é null.
CreateGlobalFunctions() foi chamado anteriormente.
Exemplos
O exemplo de código a seguir ilustra o uso de DefineGlobalMethod um método independente de tipo vinculado ao atual ModuleBuilder. Depois de compilar o método global, CreateGlobalFunctions deve ser chamado para concluí-lo.
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.
Aplica-se a
DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])
Define um método global com o 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);
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 necessários para o tipo de retorno, como IsConst ou IsBoxed. Se o tipo de retorno não tiver modificadores personalizados necessá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 modificadores personalizados necessários, especifique null em vez de uma matriz de tipos. Se o método global não tiver argumentos ou se nenhum dos argumentos tiver exigido modificadores personalizados, 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 modificadores personalizados opcionais, especifique null em vez de uma matriz 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 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 Type matriz é null.
name é null.
O CreateGlobalFunctions() método 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.