Type.IsGenericParameter Property

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 Overridable ReadOnly Property IsGenericParameter As Boolean

Property Value

Type: System.Boolean
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 Then
   ' If this is a generic type, display the type arguments.
   Dim typeArguments As Type() = t.GetGenericArguments()

   outputBlock.Text &= vbTab & "List type arguments (" _
       & typeArguments.Length & "):" & vbCrLf

   For Each tParam As Type In typeArguments
      ' If this is a type parameter, display its position.
      If tParam.IsGenericParameter Then
         outputBlock.Text &= vbTab & vbTab & tParam.ToString() & _
             vbTab & "(unassigned - parameter position " _
             & tParam.GenericParameterPosition & ")"
         outputBlock.Text &= vbTab & vbTab & tParam.ToString() & vbCrLf
      End If
   Next tParam
End If


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions