TypeBuilder.DefineMethod Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Agrega un método al tipo .
Sobrecargas
| Nombre | Description |
|---|---|
| DefineMethod(String, MethodAttributes) |
Agrega un nuevo método al tipo, con el nombre y los atributos de método especificados. |
| DefineMethod(String, MethodAttributes, CallingConventions) |
Agrega un nuevo método al tipo, con el nombre especificado, los atributos de método y la convención de llamada. |
| DefineMethod(String, MethodAttributes, Type, Type[]) |
Agrega un nuevo método al tipo, con el nombre, los atributos de método y la firma de método especificados. |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[]) |
Agrega un nuevo método al tipo, con el nombre especificado, los atributos del método, la convención de llamada y la firma del método. |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][]) |
Agrega un nuevo método al tipo, con el nombre especificado, los atributos de método, la convención de llamada, la firma del método y los modificadores personalizados especificados. |
DefineMethod(String, MethodAttributes)
Agrega un nuevo método al tipo, con el nombre y los atributos de método especificados.
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
Nombre del método.
name no puede contener valores NULL incrustados.
- attributes
- MethodAttributes
Atributos del método .
Devoluciones
que MethodBuilder representa el método recién definido.
Excepciones
La longitud de name es cero.
O bien
El tipo del elemento primario de este método es una interfaz y este método no es virtual (Overridable en Visual Basic).
name es null.
El tipo se creó anteriormente mediante CreateType().
O bien
Para el tipo dinámico actual, la IsGenericType propiedad es true, pero la IsGenericTypeDefinition propiedad es false.
Ejemplos
En el ejemplo de código siguiente se define un método genérico denominado DemoMethod cuyo tipo de parámetro y tipo de valor devuelto se especifican mediante sus parámetros de tipo genérico. El método se define sin una firma mediante la convención de llamada estándar. El MethodBuilder.DefineGenericParameters método se usa para crear DemoMethod un método genérico y los parámetros de tipo recién definidos se usan para la firma y el tipo de valor devuelto.
Este ejemplo de código forma parte de un ejemplo más grande proporcionado para el 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))
Comentarios
Use esta sobrecarga de método cuando no conozca la firma del método en el momento en que defina el método. Por ejemplo, los tipos de parámetro y el tipo de valor devuelto de un método genérico pueden especificarse mediante los parámetros de tipo genérico del método, que se deben definir después de agregar el método al tipo. Los parámetros y el tipo de valor devuelto del método se pueden establecer más adelante mediante el MethodBuilder.SetSignature método .
Esta sobrecarga de método define un método con CallingConventions.Standard. Si necesita definir un método sin una firma, con una convención de llamada diferente, use la sobrecarga del DefineMethod(String, MethodAttributes, CallingConventions) método.
Consulte también
Se aplica a
DefineMethod(String, MethodAttributes, CallingConventions)
Agrega un nuevo método al tipo, con el nombre especificado, los atributos de método y la convención de llamada.
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
Nombre del método.
name no puede contener valores NULL incrustados.
- attributes
- MethodAttributes
Atributos del método .
- callingConvention
- CallingConventions
Convención de llamada del método .
Devoluciones
que MethodBuilder representa el método recién definido.
Excepciones
La longitud de name es cero.
O bien
El tipo del elemento primario de este método es una interfaz y este método no es virtual (Overridable en Visual Basic).
name es null.
El tipo se creó anteriormente mediante CreateType().
O bien
Para el tipo dinámico actual, la IsGenericType propiedad es true, pero la IsGenericTypeDefinition propiedad es false.
Comentarios
Use esta sobrecarga de método cuando no conozca la firma del método en el momento en que defina el método. Por ejemplo, los tipos de parámetro y el tipo de valor devuelto de un método genérico pueden especificarse mediante los parámetros de tipo genérico del método, que se deben definir después de agregar el método al tipo. Los parámetros y el tipo de valor devuelto del método se pueden establecer más adelante mediante el MethodBuilder.SetSignature método .
Consulte también
Se aplica a
DefineMethod(String, MethodAttributes, Type, Type[])
Agrega un nuevo método al tipo, con el nombre, los atributos de método y la firma de método especificados.
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
Nombre del método.
name no puede contener valores NULL incrustados.
- attributes
- MethodAttributes
Atributos del 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 definido.
Excepciones
La longitud de name es cero.
O bien
El tipo del elemento primario de este método es una interfaz y este método no es virtual (Overridable en Visual Basic).
name es null.
El tipo se creó anteriormente mediante CreateType().
O bien
Para el tipo dinámico actual, la IsGenericType propiedad es true, pero la IsGenericTypeDefinition propiedad es false.
Ejemplos
En el ejemplo de código siguiente se muestra el uso de para establecer la firma y los atributos concretos de DefineMethod un constructor en un tipo dinámico y devolver un correspondiente MethodBuilder para el rellenado de 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
Se aplica a
DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[])
Agrega un nuevo método al tipo, con el nombre especificado, los atributos del método, la convención de llamada y la firma del 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
Nombre del método.
name no puede contener valores NULL incrustados.
- attributes
- MethodAttributes
Atributos del método .
- callingConvention
- CallingConventions
Convención de llamada del método .
- returnType
- Type
Tipo de valor devuelto del método .
- parameterTypes
- Type[]
Los tipos de los parámetros del método .
Devoluciones
que MethodBuilder representa el método recién definido.
Excepciones
La longitud de name es cero.
O bien
El tipo del elemento primario de este método es una interfaz y este método no es virtual (Overridable en Visual Basic).
name es null.
El tipo se creó anteriormente mediante CreateType().
O bien
Para el tipo dinámico actual, la IsGenericType propiedad es true, pero la IsGenericTypeDefinition propiedad es false.
Ejemplos
En el ejemplo de código siguiente se muestra el uso de para establecer la firma y los atributos concretos de DefineMethod un constructor en un tipo dinámico y devolver un correspondiente MethodBuilder para el rellenado de 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
Se aplica a
DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])
Agrega un nuevo método al tipo, con el nombre especificado, los atributos de método, la convención de llamada, la firma del método y los modificadores personalizados especificados.
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
Nombre del método.
name no puede contener valores NULL incrustados.
- attributes
- MethodAttributes
Atributos del método .
- callingConvention
- CallingConventions
Convención de llamada del método .
- returnType
- Type
Tipo de valor devuelto del método .
- returnTypeRequiredCustomModifiers
- Type[]
Matriz de tipos que representan los modificadores personalizados necesarios, como IsConst, para el tipo de valor devuelto del método . Si el tipo de valor devuelto no tiene modificadores personalizados necesarios, especifique null.
- returnTypeOptionalCustomModifiers
- Type[]
Matriz de tipos que representan los modificadores personalizados opcionales, como IsConst, para el tipo de valor devuelto del método . Si el tipo de valor devuelto no tiene modificadores personalizados opcionales, especifique null.
- parameterTypes
- Type[]
Los tipos de los parámetros del método .
- parameterTypeRequiredCustomModifiers
- Type[][]
Matriz de matrices de tipos. Cada matriz de tipos representa los modificadores personalizados necesarios para el parámetro correspondiente, como IsConst. Si un parámetro determinado no tiene modificadores personalizados necesarios, especifique null en lugar de una matriz de tipos. Si ninguno de los parámetros tiene modificadores personalizados necesarios, especifique null en lugar de una matriz de matrices.
- parameterTypeOptionalCustomModifiers
- Type[][]
Matriz de matrices de tipos. Cada matriz de tipos representa los modificadores personalizados opcionales para el parámetro correspondiente, como IsConst. Si un parámetro determinado no tiene modificadores personalizados opcionales, especifique null en lugar de una matriz de tipos. Si ninguno de los parámetros tiene modificadores personalizados opcionales, especifique null en lugar de una matriz de matrices.
Devoluciones
Objeto MethodBuilder que representa el método recién agregado.
Excepciones
La longitud de name es cero.
O bien
El tipo del elemento primario de este método es una interfaz y este método no es virtual (Overridable en Visual Basic).
O bien
El tamaño de parameterTypeRequiredCustomModifiers o parameterTypeOptionalCustomModifiers no es igual al tamaño de parameterTypes.
name es null.
El tipo se creó anteriormente mediante CreateType().
O bien
Para el tipo dinámico actual, la IsGenericType propiedad es true, pero la IsGenericTypeDefinition propiedad es false.
Comentarios
Use esta sobrecarga si necesita especificar modificadores personalizados. Si necesita especificar modificadores personalizados después de crear el método, como lo haría, por ejemplo, con un método genérico cuyos tipos de parámetro se especifican mediante sus parámetros de tipo genérico, puede usar las DefineMethod(String, MethodAttributes) sobrecargas de método o DefineMethod(String, MethodAttributes, CallingConventions) para definir el método y, a continuación, usar el MethodBuilder.SetSignature método para definir el parámetro y los tipos devueltos con modificadores personalizados.
Note
Para obtener más información sobre los modificadores personalizados, consulte ECMA C# y Common Language Infrastructure Standards and Standard ECMA-335 - Common Language Infrastructure (CLI).