TypeBuilder.DefineMethod Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Adiciona um método ao tipo.
Sobrecargas
| Name | Description |
|---|---|
| DefineMethod(String, MethodAttributes) |
Adiciona um novo método ao tipo, com o nome especificado e os atributos do método. |
| DefineMethod(String, MethodAttributes, CallingConventions) |
Adiciona um novo método ao tipo, com o nome especificado, atributos do método e convenção de chamada. |
| DefineMethod(String, MethodAttributes, Type, Type[]) |
Adiciona um novo método ao tipo, com o nome especificado, atributos do método e assinatura do método. |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[]) |
Adiciona um novo método ao tipo, com o nome especificado, atributos do método, convenção de chamada e assinatura do método. |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][]) |
Adiciona um novo método ao tipo, com o nome especificado, atributos do método, convenção de chamada, assinatura do método e modificadores personalizados. |
DefineMethod(String, MethodAttributes)
Adiciona um novo método ao tipo, com o nome especificado e os atributos do método.
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes);
member this.DefineMethod : string * System.Reflection.MethodAttributes -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes) 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.
Devoluções
A MethodBuilder representa o método recém-definido.
Exceções
O comprimento de name é zero.
-ou-
O tipo do pai deste método é uma interface, e este método não é virtual (Overridable em Visual Basic).
name é null.
O tipo foi anteriormente criado usando CreateType().
-ou-
Para o tipo dinâmico atual, a IsGenericType propriedade é true, mas a IsGenericTypeDefinition propriedade é false.
Exemplos
O seguinte exemplo de código define um método genérico nomeado DemoMethod cujo tipo de parâmetro e tipo de retorno são especificados pelos seus parâmetros genéricos de tipo. O método é definido sem assinatura, usando a convenção padrão de chamada. O MethodBuilder.DefineGenericParameters método é usado para criar DemoMethod um método genérico, e os parâmetros de tipo recém-definidos são então usados para a assinatura e o tipo de retorno.
Este exemplo de código faz parte de um exemplo maior fornecido para o DefineGenericParameters método.
// Define a Shared, Public method with standard calling
// conventions. Do not specify the parameter types or the
// return type, because type parameters will be used for
// those types, and the type parameters have not been
// defined yet.
MethodBuilder demoMethod = demoType.DefineMethod(
"DemoMethod",
MethodAttributes.Public | MethodAttributes.Static
);
' Define a Shared, Public method with standard calling
' conventions. Do not specify the parameter types or the
' return type, because type parameters will be used for
' those types, and the type parameters have not been
' defined yet.
Dim demoMethod As MethodBuilder = _
demoType.DefineMethod("DemoMethod", _
MethodAttributes.Public Or MethodAttributes.Static)
// Defining generic parameters for the method makes it a
// generic method. By convention, type parameters are
// single alphabetic characters. T and U are used here.
//
string[] typeParamNames = {"T", "U"};
GenericTypeParameterBuilder[] typeParameters =
demoMethod.DefineGenericParameters(typeParamNames);
// The second type parameter is constrained to be a
// reference type.
typeParameters[1].SetGenericParameterAttributes(
GenericParameterAttributes.ReferenceTypeConstraint);
' Defining generic parameters for the method makes it a
' generic method. By convention, type parameters are
' single alphabetic characters. T and U are used here.
'
Dim typeParamNames() As String = {"T", "U"}
Dim typeParameters() As GenericTypeParameterBuilder = _
demoMethod.DefineGenericParameters(typeParamNames)
' The second type parameter is constrained to be a
' reference type.
typeParameters(1).SetGenericParameterAttributes( _
GenericParameterAttributes.ReferenceTypeConstraint)
// Set parameter types for the method. The method takes
// one parameter, and its type is specified by the first
// type parameter, T.
Type[] parms = {typeParameters[0]};
demoMethod.SetParameters(parms);
// Set the return type for the method. The return type is
// specified by the second type parameter, U.
demoMethod.SetReturnType(typeParameters[1]);
' Set parameter types for the method. The method takes
' one parameter, and its type is specified by the first
' type parameter, T.
Dim params() As Type = {typeParameters(0)}
demoMethod.SetParameters(params)
' Set the return type for the method. The return type is
' specified by the second type parameter, U.
demoMethod.SetReturnType(typeParameters(1))
Observações
Use esta sobrecarga de métodos quando não conhece a assinatura do método no momento em que define o método. Por exemplo, os tipos de parâmetros e o tipo de retorno de um método genérico podem ser especificados pelos parâmetros genéricos do tipo, que devem ser definidos depois de o método ter sido adicionado ao tipo. Os parâmetros e o tipo de retorno do método podem ser definidos posteriormente usando o MethodBuilder.SetSignature método.
Esta sobrecarga de métodos define um método com CallingConventions.Standard. Se precisar de definir um método sem assinatura, com uma convenção de chamada diferente, use o DefineMethod(String, MethodAttributes, CallingConventions) método de sobrecarga.
Ver também
Aplica-se a
DefineMethod(String, MethodAttributes, CallingConventions)
Adiciona um novo método ao tipo, com o nome especificado, atributos do método e convenção de chamada.
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention);
member this.DefineMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions) 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.
- callingConvention
- CallingConventions
A convenção de chamada do método.
Devoluções
A MethodBuilder representa o método recém-definido.
Exceções
O comprimento de name é zero.
-ou-
O tipo de pai deste método é uma interface e este método não é virtual (Overridable em Visual Basic).
name é null.
O tipo foi anteriormente criado usando CreateType().
-ou-
Para o tipo dinâmico atual, a IsGenericType propriedade é true, mas a IsGenericTypeDefinition propriedade é false.
Observações
Use esta sobrecarga de métodos quando não conhece a assinatura do método no momento em que define o método. Por exemplo, os tipos de parâmetros e o tipo de retorno de um método genérico podem ser especificados pelos parâmetros genéricos do tipo, que devem ser definidos depois de o método ter sido adicionado ao tipo. Os parâmetros e o tipo de retorno do método podem ser definidos posteriormente usando o MethodBuilder.SetSignature método.
Ver também
Aplica-se a
DefineMethod(String, MethodAttributes, Type, Type[])
Adiciona um novo método ao tipo, com o nome especificado, atributos do método e assinatura do método.
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, Type returnType, Type[] parameterTypes);
member this.DefineMethod : string * System.Reflection.MethodAttributes * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (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.
- returnType
- Type
O tipo de retorno do método.
- parameterTypes
- Type[]
Os tipos de parâmetros do método.
Devoluções
O método definido.
Exceções
O comprimento de name é zero.
-ou-
O tipo do pai deste método é uma interface, e este método não é virtual (Overridable em Visual Basic).
name é null.
O tipo foi anteriormente criado usando CreateType().
-ou-
Para o tipo dinâmico atual, a IsGenericType propriedade é true, mas a IsGenericTypeDefinition propriedade é false.
Exemplos
O exemplo de código seguinte demonstra a utilização de DefineMethod para definir a assinatura e atributos particulares de um construtor num tipo dinâmico e para retornar um correspondente MethodBuilder para a população MSIL.
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
using System.Security.Permissions;
public interface IMyInterface
{
String HelloMethod(String parameter);
}
public class Example
{
public static void Main()
{
Type myNestedClassType = CreateCallee(Thread.GetDomain());
// Cretae an instance of 'MyNestedClass'.
IMyInterface myInterface =
(IMyInterface)Activator.CreateInstance(myNestedClassType);
Console.WriteLine(myInterface.HelloMethod("Bill"));
}
// Create the callee transient dynamic assembly.
private static Type CreateCallee(AppDomain myAppDomain)
{
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "Example";
// Create the callee dynamic assembly.
AssemblyBuilder myAssembly =
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module in the callee assembly.
ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule");
// Define a public class named "MyHelloWorld".
TypeBuilder myHelloWorldType =
myModule.DefineType("MyHelloWorld", TypeAttributes.Public);
// Define a public nested class named 'MyNestedClass'.
TypeBuilder myNestedClassType =
myHelloWorldType.DefineNestedType("MyNestedClass",
TypeAttributes.NestedPublic, typeof(Example),
new Type[]{typeof(IMyInterface)});
// Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(typeof(IMyInterface));
// Define 'HelloMethod' of 'IMyInterface'.
MethodBuilder myHelloMethod =
myNestedClassType.DefineMethod("HelloMethod",
MethodAttributes.Public | MethodAttributes.Virtual,
typeof(String), new Type[]{typeof(String)});
// Generate IL for 'GetGreeting' method.
ILGenerator myMethodIL = myHelloMethod.GetILGenerator();
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ");
myMethodIL.Emit(OpCodes.Ldarg_1);
MethodInfo infoMethod =
typeof(String).GetMethod("Concat",new Type[]{typeof(string),typeof(string)});
myMethodIL.Emit(OpCodes.Call, infoMethod);
myMethodIL.Emit(OpCodes.Ret);
MethodInfo myHelloMethodInfo =
typeof(IMyInterface).GetMethod("HelloMethod");
// Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo);
// Create 'MyHelloWorld' type.
Type myType = myHelloWorldType.CreateType();
// Create 'MyNestedClass' type.
return myNestedClassType.CreateType();
}
}
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Security.Permissions
Public Interface IMyInterface
Function HelloMethod(parameter As String) As String
End Interface 'IMyInterface
Public Class Example
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Shared Sub Main()
Dim myNestedClassType As Type = CreateCallee(Thread.GetDomain())
' Create an instance of 'MyNestedClass'.
Dim myInterface As IMyInterface = _
CType(Activator.CreateInstance(myNestedClassType), IMyInterface)
Console.WriteLine(myInterface.HelloMethod("Bill"))
End Sub
' Create the callee transient dynamic assembly.
Private Shared Function CreateCallee(myAppDomain As AppDomain) As Type
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "Example"
' Create the callee dynamic assembly.
Dim myAssembly As AssemblyBuilder = _
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
' Create a dynamic module in the callee assembly.
Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule("EmittedModule")
' Define a public class named "MyHelloWorld".
Dim myHelloWorldType As TypeBuilder = _
myModule.DefineType("MyHelloWorld", TypeAttributes.Public)
' Define a public nested class named 'MyNestedClass'.
Dim myNestedClassType As TypeBuilder = _
myHelloWorldType.DefineNestedType("MyNestedClass", TypeAttributes.NestedPublic, _
GetType(Example), New Type() {GetType(IMyInterface)})
' Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(GetType(IMyInterface))
' Define 'HelloMethod' of 'IMyInterface'.
Dim myHelloMethod As MethodBuilder = _
myNestedClassType.DefineMethod("HelloMethod", MethodAttributes.Public Or _
MethodAttributes.Virtual, GetType(String), New Type() {GetType(String)})
' Generate IL for 'GetGreeting' method.
Dim myMethodIL As ILGenerator = myHelloMethod.GetILGenerator()
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ")
myMethodIL.Emit(OpCodes.Ldarg_1)
Dim infoMethod As MethodInfo = _
GetType(String).GetMethod("Concat", New Type() {GetType(String), GetType(String)})
myMethodIL.Emit(OpCodes.Call, infoMethod)
myMethodIL.Emit(OpCodes.Ret)
Dim myHelloMethodInfo As MethodInfo = GetType(IMyInterface).GetMethod("HelloMethod")
' Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo)
' Create 'MyHelloWorld' type.
Dim myType As Type = myHelloWorldType.CreateType()
' Create 'MyNestedClass' type.
Return myNestedClassType.CreateType()
End Function 'CreateCallee
End Class
Aplica-se a
DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[])
Adiciona um novo método ao tipo, com o nome especificado, atributos do método, convenção de chamada e assinatura do método.
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes);
member this.DefineMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (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.
- callingConvention
- CallingConventions
A convenção de chamada do método.
- returnType
- Type
O tipo de retorno do método.
- parameterTypes
- Type[]
Os tipos de parâmetros do método.
Devoluções
A MethodBuilder representa o método recém-definido.
Exceções
O comprimento de name é zero.
-ou-
O tipo do pai deste método é uma interface, e este método não é virtual (Overridable em Visual Basic).
name é null.
O tipo foi anteriormente criado usando CreateType().
-ou-
Para o tipo dinâmico atual, a IsGenericType propriedade é true, mas a IsGenericTypeDefinition propriedade é false.
Exemplos
O exemplo de código seguinte demonstra a utilização de DefineMethod para definir a assinatura e atributos particulares de um construtor num tipo dinâmico e para retornar um correspondente MethodBuilder para a população MSIL.
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
using System.Security.Permissions;
public interface IMyInterface
{
String HelloMethod(String parameter);
}
public class Example
{
public static void Main()
{
Type myNestedClassType = CreateCallee(Thread.GetDomain());
// Cretae an instance of 'MyNestedClass'.
IMyInterface myInterface =
(IMyInterface)Activator.CreateInstance(myNestedClassType);
Console.WriteLine(myInterface.HelloMethod("Bill"));
}
// Create the callee transient dynamic assembly.
private static Type CreateCallee(AppDomain myAppDomain)
{
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "Example";
// Create the callee dynamic assembly.
AssemblyBuilder myAssembly =
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module in the callee assembly.
ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule");
// Define a public class named "MyHelloWorld".
TypeBuilder myHelloWorldType =
myModule.DefineType("MyHelloWorld", TypeAttributes.Public);
// Define a public nested class named 'MyNestedClass'.
TypeBuilder myNestedClassType =
myHelloWorldType.DefineNestedType("MyNestedClass",
TypeAttributes.NestedPublic, typeof(Example),
new Type[]{typeof(IMyInterface)});
// Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(typeof(IMyInterface));
// Define 'HelloMethod' of 'IMyInterface'.
MethodBuilder myHelloMethod =
myNestedClassType.DefineMethod("HelloMethod",
MethodAttributes.Public | MethodAttributes.Virtual,
typeof(String), new Type[]{typeof(String)});
// Generate IL for 'GetGreeting' method.
ILGenerator myMethodIL = myHelloMethod.GetILGenerator();
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ");
myMethodIL.Emit(OpCodes.Ldarg_1);
MethodInfo infoMethod =
typeof(String).GetMethod("Concat",new Type[]{typeof(string),typeof(string)});
myMethodIL.Emit(OpCodes.Call, infoMethod);
myMethodIL.Emit(OpCodes.Ret);
MethodInfo myHelloMethodInfo =
typeof(IMyInterface).GetMethod("HelloMethod");
// Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo);
// Create 'MyHelloWorld' type.
Type myType = myHelloWorldType.CreateType();
// Create 'MyNestedClass' type.
return myNestedClassType.CreateType();
}
}
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Security.Permissions
Public Interface IMyInterface
Function HelloMethod(parameter As String) As String
End Interface 'IMyInterface
Public Class Example
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Shared Sub Main()
Dim myNestedClassType As Type = CreateCallee(Thread.GetDomain())
' Create an instance of 'MyNestedClass'.
Dim myInterface As IMyInterface = _
CType(Activator.CreateInstance(myNestedClassType), IMyInterface)
Console.WriteLine(myInterface.HelloMethod("Bill"))
End Sub
' Create the callee transient dynamic assembly.
Private Shared Function CreateCallee(myAppDomain As AppDomain) As Type
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "Example"
' Create the callee dynamic assembly.
Dim myAssembly As AssemblyBuilder = _
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
' Create a dynamic module in the callee assembly.
Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule("EmittedModule")
' Define a public class named "MyHelloWorld".
Dim myHelloWorldType As TypeBuilder = _
myModule.DefineType("MyHelloWorld", TypeAttributes.Public)
' Define a public nested class named 'MyNestedClass'.
Dim myNestedClassType As TypeBuilder = _
myHelloWorldType.DefineNestedType("MyNestedClass", TypeAttributes.NestedPublic, _
GetType(Example), New Type() {GetType(IMyInterface)})
' Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(GetType(IMyInterface))
' Define 'HelloMethod' of 'IMyInterface'.
Dim myHelloMethod As MethodBuilder = _
myNestedClassType.DefineMethod("HelloMethod", MethodAttributes.Public Or _
MethodAttributes.Virtual, GetType(String), New Type() {GetType(String)})
' Generate IL for 'GetGreeting' method.
Dim myMethodIL As ILGenerator = myHelloMethod.GetILGenerator()
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ")
myMethodIL.Emit(OpCodes.Ldarg_1)
Dim infoMethod As MethodInfo = _
GetType(String).GetMethod("Concat", New Type() {GetType(String), GetType(String)})
myMethodIL.Emit(OpCodes.Call, infoMethod)
myMethodIL.Emit(OpCodes.Ret)
Dim myHelloMethodInfo As MethodInfo = GetType(IMyInterface).GetMethod("HelloMethod")
' Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo)
' Create 'MyHelloWorld' type.
Dim myType As Type = myHelloWorldType.CreateType()
' Create 'MyNestedClass' type.
Return myNestedClassType.CreateType()
End Function 'CreateCallee
End Class
Aplica-se a
DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])
Adiciona um novo método ao tipo, com o nome especificado, atributos do método, convenção de chamada, assinatura do método e modificadores personalizados.
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ returnTypeRequiredCustomModifiers, cli::array <Type ^> ^ returnTypeOptionalCustomModifiers, cli::array <Type ^> ^ parameterTypes, cli::array <cli::array <Type ^> ^> ^ parameterTypeRequiredCustomModifiers, cli::array <cli::array <Type ^> ^> ^ parameterTypeOptionalCustomModifiers);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers);
member this.DefineMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * Type[] * Type[] * Type[][] * Type[][] -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, returnTypeRequiredCustomModifiers As Type(), returnTypeOptionalCustomModifiers As Type(), parameterTypes As Type(), parameterTypeRequiredCustomModifiers As Type()(), parameterTypeOptionalCustomModifiers 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.
- callingConvention
- CallingConventions
A convenção de chamada do método.
- returnType
- Type
O tipo de retorno do método.
- returnTypeRequiredCustomModifiers
- Type[]
Um array de tipos que representam os modificadores personalizados necessários, como IsConst, para o tipo de retorno do método. Se o tipo de retorno não tiver modificadores personalizados obrigatórios, especifique null.
- returnTypeOptionalCustomModifiers
- Type[]
Um array de tipos que representam os modificadores personalizados opcionais, como IsConst, para o tipo de retorno do método. Se o tipo de retorno não tiver modificadores personalizados opcionais, especifique null.
- parameterTypes
- Type[]
Os tipos de parâmetros do método.
- parameterTypeRequiredCustomModifiers
- Type[][]
Uma variedade de arrays de tipos. Cada array de tipos representa os modificadores personalizados necessários para o parâmetro correspondente, como IsConst. Se um determinado parâmetro não tiver modificadores personalizados obrigatórios, especifique null em vez disso um array de tipos. Se nenhum dos parâmetros exigir modificadores personalizados, especifique null em vez de um array de arrays.
- parameterTypeOptionalCustomModifiers
- Type[][]
Uma variedade de arrays de tipos. Cada array de tipos representa os modificadores personalizados opcionais para o parâmetro correspondente, como IsConst. Se um determinado parâmetro não tiver modificadores personalizados opcionais, especifique null em vez disso um array de tipos. Se nenhum dos parâmetros tiver modificadores personalizados opcionais, especifique null em vez de um array de arrays.
Devoluções
Um MethodBuilder objeto que representa o método recém-adicionado.
Exceções
O comprimento de name é zero.
-ou-
O tipo do pai deste método é uma interface, e este método não é virtual (Overridable em Visual Basic).
-ou-
O tamanho de parameterTypeRequiredCustomModifiers ou parameterTypeOptionalCustomModifiers não é igual ao tamanho de parameterTypes.
name é null.
O tipo foi anteriormente criado usando CreateType().
-ou-
Para o tipo dinâmico atual, a IsGenericType propriedade é true, mas a IsGenericTypeDefinition propriedade é false.
Observações
Usa esta sobrecarga se precisares de especificar modificadores personalizados. Se precisares de especificar modificadores personalizados depois de o método ter sido criado, como farias, por exemplo, com um método genérico cujos tipos de parâmetros são especificados pelos seus parâmetros genéricos, podes usar as DefineMethod(String, MethodAttributes) sobrecargas de método ou DefineMethod(String, MethodAttributes, CallingConventions) para definir o método e depois usar o MethodBuilder.SetSignature método para definir o parâmetro e devolver tipos com modificadores personalizados.
Note
Para mais informações sobre modificadores personalizados, consulte ECMA C# e Common Language Infrastructure Standards e Standard ECMA-335 - Common Language Infrastructure (CLI).