Share via


MethodBuilder.SetParameters(Type[]) Yöntem

Tanım

Bir yöntem için parametre sayısını ve türlerini ayarlar.

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

Parametreler

parameterTypes
Type[]

Parametre türlerini temsil eden bir nesne dizisi Type .

Özel durumlar

Geçerli yöntem geneldir, ancak genel bir yöntem tanımı değildir. Başka bir ifadeyle IsGenericMethod , özelliği şeklindedir true, ancak IsGenericMethodDefinition özelliği şeklindedir false.

Örnekler

Aşağıdaki kod örneği, yöntemini genel hale getirmek için yöntemini kullanır DefineGenericParameters . SetParameters yöntemi yöntemine türü ilk genel tür parametresi tarafından belirtilecek olan bir parametre vermek için kullanılır. yöntemine SetReturnType ikinci genel tür parametresi tarafından belirtilen bir dönüş türü vermek için kullanılır.

Bu kod, yöntemi için DefineGenericParameters sağlanan daha büyük bir örneğin bir parçasıdır.

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

Açıklamalar

Yöntem tanımlandığında parametrelerin sayısı ve türleri biliniyorsa, parametre türleri dizisini kabul eden yöntemin TypeBuilder.DefineMethod herhangi bir aşırı yüklemesi kullanılarak ayarlanabilirler. Ancak, genel bir yöntem, türleri kendi genel tür parametrelerinden biri veya daha fazlası tarafından belirtilen parametrelere sahip olabilir ve yöntem tanımlandıktan sonra tanımlanamaz. Bu durumda parametre türlerini ayarlamak için bu yöntemi kullanın.

Dönüş türü gibi isteğe bağlı veya gerekli özel değiştiricilere IsConstsahipse yöntem aşırı yüklemesini SetSignature(Type, Type[], Type[], Type[], Type[][], Type[][]) kullanın.

Bu yöntemi çağırmak, yöntemi kullanılarak ayarlanan tüm parametre türlerinin TypeBuilder.DefineMethod yerini alır.

Şunlara uygulanır

Ayrıca bkz.