Sdílet prostřednictvím


Type.IsGenericParameter Vlastnost

Definice

Získá hodnotu určující, zda aktuální Type představuje typ parametr v definici obecného typu nebo metody.

public:
 abstract property bool IsGenericParameter { bool get(); };
public:
 virtual property bool IsGenericParameter { bool get(); };
public abstract bool IsGenericParameter { get; }
public virtual bool IsGenericParameter { get; }
member this.IsGenericParameter : bool
Public MustOverride ReadOnly Property IsGenericParameter As Boolean
Public Overridable ReadOnly Property IsGenericParameter As Boolean

Hodnota vlastnosti

true Type pokud objekt představuje parametr typu definice obecného typu nebo definice obecné metody; jinak , false.

Příklady

Následující příklad používá IsGenericParameter vlastnost testovat parametry obecného typu v obecném typu.

if (t.IsGenericType)
{
    // If this is a generic type, display the type arguments.
    //
    Type[] typeArguments = t.GetGenericArguments();

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

    foreach (Type tParam in typeArguments)
    {
        // If this is a type parameter, display its
        // position.
        //
        if (tParam.IsGenericParameter)
        {
            Console.WriteLine("\t\t{0}\t(unassigned - parameter position {1})",
                tParam,
                tParam.GenericParameterPosition);
        }
        else
        {
            Console.WriteLine("\t\t{0}", tParam);
        }
    }
}
if t.IsGenericType then
    // If this is a generic type, display the type arguments.
    let typeArguments = t.GetGenericArguments()

    printfn $"\tList type arguments ({typeArguments.Length}):" 

    for tParam in typeArguments do
        // If this is a type parameter, display its position.
        if tParam.IsGenericParameter then
            printfn $"\t\t{tParam}\t(unassigned - parameter position {tParam.GenericParameterPosition})"
        else
            printfn $"\t\t{tParam}"
If t.IsGenericType Then
    ' If this is a generic type, display the type arguments.
    '
    Dim typeArguments As Type() = t.GetGenericArguments()
    
    Console.WriteLine(vbTab & "List type arguments (" _
        & typeArguments.Length & "):")
    
    For Each tParam As Type In typeArguments
        ' If this is a type parameter, display its position.
        '
        If tParam.IsGenericParameter Then
            Console.WriteLine(vbTab & vbTab & tParam.ToString() _
                & vbTab & "(unassigned - parameter position " _
                & tParam.GenericParameterPosition & ")")
        Else
            Console.WriteLine(vbTab & vbTab & tParam.ToString())
        End If
    Next tParam
End If

Poznámky

Type objekty, které představují parametry obecného typu lze získat voláním GetGenericArguments metody Type objektu, který představuje definici obecného typu nebo GetGenericArguments metodu MethodInfo objektu, který představuje definici obecné metody.

  • Pro obecný typ nebo definici IsGenericParameter metody vrátí true vlastnost pro každý prvek výsledného pole.

  • U uzavřeného vytvořeného typu nebo metody IsGenericParameter vrátí false vlastnost pro každý prvek pole vrácené metodou GetGenericArguments .

  • U otevřeného vytvořeného typu nebo metody mohou být některé prvky pole specifické typy a jiné můžou být parametry typu. IsGenericParameter vrátí false pro typy a true parametry typu. Příklad kódu pro ContainsGenericParameters vlastnost ukazuje obecnou třídu se kombinací typů a parametrů typu.

Seznam invariantních podmínek pro termíny použité v obecné reflexi najdete v IsGenericType poznámkách k vlastnostem.

Platí pro

Viz také