Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.IsGenericParameter Property

Note: This property is new in the .NET Framework version 2.0.

Gets a value indicating whether the current Type represents a type parameter in the definition of a generic type or method.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public virtual bool IsGenericParameter { get; }
/** @property */
public boolean get_IsGenericParameter ()

public function get IsGenericParameter () : boolean

Property Value

true if the Type object represents a type parameter of a generic type definition or generic method definition; otherwise, false.

Type objects that represent generic type parameters can be obtained by calling the GetGenericArguments method of a Type object that represents a generic type definition, or the GetGenericArguments method of a MethodInfo object that represents a generic method definition.

  • For a generic type or method definition, the IsGenericParameter property returns true for every element of the resulting array.

  • For a closed constructed type or method, the IsGenericParameter property returns false for every element of the array returned by the GetGenericArguments method.

  • For an open constructed type or method, some elements of the array might be specific types and others might be type parameters. IsGenericParameter returns false for the types and true for the type parameters. The code example for the ContainsGenericParameters property demonstrates a generic class with a mixture of types and type parameters.

For a list of the invariant conditions for terms used in generic reflection, see the IsGenericType property remarks.

The following example uses the IsGenericParameter property to test for generic type parameters in a generic type.

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.get_IsGenericType()) {
    // If this is a generic type, display the type arguments.
    Type typeArguments[] = t.GetGenericArguments();
    Console.WriteLine("\tList type arguments ({0}):",
        (Int32)typeArguments.get_Length());
    for (int iCtr = 0; iCtr < typeArguments.get_Length(); iCtr++) {
        Type tParam = typeArguments[iCtr];
        // If this is a type parameter, display its
        // position.
        
        if (tParam.get_IsGenericParameter()) {
            Console.WriteLine("\t\t{0}\t(unassigned - parameter "
                + "position {1})", tParam, 
                (Int32)tParam.get_GenericParameterPosition());
        }
        else {
            Console.WriteLine("\t\t{0}", tParam);
        }
    }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0

Community Additions

Show:
© 2014 Microsoft