MethodBuilder.SetParameters(Type[]) Método

Definición

Establece el número y los tipos de parámetros de un método.

public:
 void SetParameters(... cli::array <Type ^> ^ parameterTypes);
public:
 void SetParameters(cli::array <Type ^> ^ parameterTypes);
public void SetParameters (params Type[] parameterTypes);
public void SetParameters (Type[] parameterTypes);
member this.SetParameters : Type[] -> unit
Public Sub SetParameters (ParamArray parameterTypes As Type())
Public Sub SetParameters (parameterTypes As Type())

Parámetros

parameterTypes
Type[]

Matriz de objetos Type que representan los tipos de parámetros.

Excepciones

El método actual es genérico, pero no es una definición de método genérico. Es decir, la propiedad IsGenericMethod es true, pero la propiedad IsGenericMethodDefinition es false.

Ejemplos

En el ejemplo de código siguiente se DefineGenericParameters usa el método para convertir un método en genérico. El SetParameters método se usa para proporcionar al método un parámetro, cuyo tipo se especificará mediante el primer parámetro de tipo genérico. El SetReturnType método se usa para proporcionar al método un tipo de valor devuelto, especificado por el segundo parámetro de tipo genérico.

Este código forma parte de un ejemplo mayor proporcionado para el DefineGenericParameters método .

// 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.
//
array<String^>^ genericTypeNames = {"T", "U"};
array<GenericTypeParameterBuilder^>^ genericTypes =
    sampleMethodBuilder->DefineGenericParameters(
    genericTypeNames);
// 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.
array<Type^>^ parameterTypes = {genericTypes[0]};
sampleMethodBuilder->SetParameters(parameterTypes);

// Set the return type for the method. The return type is
// specified by the second type parameter, U.
sampleMethodBuilder->SetReturnType(genericTypes[1]);
// 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

Si el número y los tipos de los parámetros se conocen cuando se define el método , se pueden establecer mediante cualquier sobrecarga del método que acepte una matriz de tipos TypeBuilder.DefineMethod de parámetro. Sin embargo, un método genérico puede tener parámetros cuyos tipos se especifican mediante uno o varios de sus propios parámetros de tipo genérico, que no se pueden definir hasta después de que se haya definido el método. Use este método para establecer los tipos de parámetro en ese caso.

Si el tipo de valor devuelto tiene modificadores personalizados opcionales o obligatorios, como IsConst , use la sobrecarga del método SetSignature(Type, Type[], Type[], Type[], Type[][], Type[][]) .

Al llamar a este método se reemplazan los tipos de parámetro que se han establecido mediante el TypeBuilder.DefineMethod método .

Se aplica a

Consulte también