MethodBuilder.SetParameters(Type[]) メソッド

定義

メソッドのパラメーターの数と型を設定します。

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

パラメーター

parameterTypes
Type[]

パラメーター型を表す Type オブジェクトの配列。

例外

現在のメソッドはジェネリックですが、ジェネリック メソッド定義ではありません。 つまり、 IsGenericMethod プロパティは trueされますが、 IsGenericMethodDefinition プロパティは false

次のコード例では、 DefineGenericParameters メソッドを使用してメソッドをジェネリックにします。 SetParameters メソッドは、メソッドに 1 つのパラメーターを指定するために使用され、その型は最初のジェネリック型パラメーターで指定されます。 SetReturnType メソッドは、2 番目のジェネリック型パラメーターで指定された戻り値の型をメソッドに与えるために使用されます。

このコードは、 DefineGenericParameters メソッドで提供されるより大きな例の一部です。

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

注釈

メソッドの定義時にパラメーターの数と型がわかっている場合は、パラメーター型の配列を受け取る TypeBuilder.DefineMethod メソッドのオーバーロードを使用して設定できます。 ただし、ジェネリック メソッドには、1 つ以上の独自のジェネリック型パラメーターによって型が指定されているパラメーターを含めることができます。このパラメーターは、メソッドが定義されるまで定義できません。 このメソッドを使用して、その場合にパラメーターの型を設定します。

戻り値の型に省略可能または必須のカスタム修飾子 ( IsConstなど) がある場合は、 SetSignature(Type, Type[], Type[], Type[], Type[][], Type[][]) メソッドのオーバーロードを使用します。

このメソッドを呼び出すと、 TypeBuilder.DefineMethod メソッドを使用して設定されたすべてのパラメーター型が置き換えられます。

適用対象

こちらもご覧ください