MethodInfo.GetGenericArguments メソッド

定義

ジェネリック メソッドの型引数、またはジェネリック メソッドの定義の型パラメーターを表す Type オブジェクトの配列を返します。

public:
 override cli::array <Type ^> ^ GetGenericArguments();
public override Type[] GetGenericArguments ();
[System.Runtime.InteropServices.ComVisible(true)]
public override Type[] GetGenericArguments ();
override this.GetGenericArguments : unit -> Type[]
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetGenericArguments : unit -> Type[]
Public Overrides Function GetGenericArguments () As Type()

戻り値

Type[]

ジェネリック メソッドの型引数またはジェネリック メソッド定義の型パラメーターを表す Type オブジェクトの配列。 現在のメソッドがジェネリック メソッドではない場合は、空の配列を返します。

属性

例外

このメソッドはサポートされていません。

次のコード例は、ジェネリック メソッドの型引数を取得して表示する方法を示しています。

この例は、メソッドに対して提供されるより大きな例の MakeGenericMethod 一部です。

// If this is a generic method, display its type arguments.
//
if (mi->IsGenericMethod)
{
    array<Type^>^ typeArguments = mi->GetGenericArguments();

    Console::WriteLine("\tList type arguments ({0}):", 
        typeArguments->Length);

    for each (Type^ tParam in typeArguments)
    {
        // IsGenericParameter is true only for generic type
        // parameters.
        //
        if (tParam->IsGenericParameter)
        {
            Console::WriteLine("\t\t{0}  parameter position {1}" +
                "\n\t\t   declaring method: {2}",
                tParam,
                tParam->GenericParameterPosition,
                tParam->DeclaringMethod);
        }
        else
        {
            Console::WriteLine("\t\t{0}", tParam);
        }
    }
}
// If this is a generic method, display its type arguments.
//
if (mi.IsGenericMethod)
{
    Type[] typeArguments = mi.GetGenericArguments();

    Console.WriteLine("\tList type arguments ({0}):",
        typeArguments.Length);

    foreach (Type tParam in typeArguments)
    {
        // IsGenericParameter is true only for generic type
        // parameters.
        //
        if (tParam.IsGenericParameter)
        {
            Console.WriteLine("\t\t{0}  parameter position {1}" +
                "\n\t\t   declaring method: {2}",
                tParam,
                tParam.GenericParameterPosition,
                tParam.DeclaringMethod);
        }
        else
        {
            Console.WriteLine("\t\t{0}", tParam);
        }
    }
}
' If this is a generic method, display its type arguments.
'
If mi.IsGenericMethod Then
    Dim typeArguments As Type() = mi.GetGenericArguments()
    
    Console.WriteLine(vbTab & "List type arguments ({0}):", _
        typeArguments.Length)
    
    For Each tParam As Type In typeArguments
        ' IsGenericParameter is true only for generic type
        ' parameters.
        '
        If tParam.IsGenericParameter Then
            Console.WriteLine(vbTab & vbTab _
                & "{0}  parameter position: {1}" _
                & vbCrLf & vbTab & vbTab _
                & "   declaring method: {2}", _
                tParam,  _
                tParam.GenericParameterPosition, _
                tParam.DeclaringMethod)
        Else
            Console.WriteLine(vbTab & vbTab & tParam.ToString())
        End If
    Next tParam
End If

注釈

返される配列の要素は、ジェネリック メソッドの型パラメーターの一覧に表示される順序になります。

  • 現在のメソッドが閉じた構築メソッド (つまり、プロパティが ContainsGenericParameters 返す false) の場合、メソッドによって GetGenericArguments 返される配列には、ジェネリック メソッド定義のジェネリック型パラメーターに割り当てられている型が含まれます。

  • 現在のメソッドがジェネリック メソッド定義の場合、配列には型パラメーターが含まれます。

  • 現在のメソッドが、一部の型パラメーターに特定の型が割り当てられ、それを囲むジェネリック型の型パラメーターが他の型パラメーターに割り当てられているオープン構築メソッド (つまり、 ContainsGenericParameters プロパティが返す true) の場合、配列には型パラメーターと型パラメーターの両方が含まれます。 プロパティを IsGenericParameter 使用して区別します。 このシナリオのデモについては、プロパティのコード例を ContainsGenericParameters 参照してください。

ジェネリック メソッドに固有の用語の不変条件の一覧については、プロパティを IsGenericMethod 参照してください。 ジェネリック リフレクションで使用される他の用語の不変条件の一覧については、プロパティを Type.IsGenericType 参照してください。

適用対象

こちらもご覧ください