This documentation is archived and is not being maintained.

Type.IsGenericTypeDefinition Property

Gets a value indicating whether the current Type represents a generic type definition, from which other generic types can be constructed.

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

'Declaration
Public Overridable ReadOnly Property IsGenericTypeDefinition As Boolean
'Usage
Dim instance As Type 
Dim value As Boolean 

value = instance.IsGenericTypeDefinition

Property Value

Type: System.Boolean
true if the Type object represents a generic type definition; otherwise, false.

A generic type definition is a template from which other types can be constructed. For example, from the generic type definition G<T> (expressed in C# syntax; G(Of T) in Visual Basic or generic <typename T> ref class G in C++) you can construct and instantiate the type G<int> (G(Of Integer) in Visual Basic), by calling the MakeGenericType method with a generic argument list containing the Int32 type. Given a Type object representing this constructed type, the GetGenericTypeDefinition method gets the generic type definition back again.

Use the IsGenericTypeDefinition property to determine whether you can create new types from the current type. If the IsGenericTypeDefinition property returns true, you can call the MakeGenericType method to create new generic types.

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

The following example displays information about a type, including whether or not it is a generic type definition. Information is displayed for a constructed type, for its generic type definition, and for an ordinary type.

Imports System
Imports System.Reflection
Imports System.Collections.Generic
Imports Microsoft.VisualBasic

Public Class Test
    Private Shared Sub DisplayGenericTypeInfo(ByVal t As Type) 
        Console.WriteLine(vbCrLf & t.ToString())

        Console.WriteLine(vbTab & "Is this a generic type definition? " _
            & t.IsGenericTypeDefinition)

        Console.WriteLine(vbTab & "Is it a generic type? " _
            & t.IsGenericType)

        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 

    End Sub  


    Public Shared Sub Main() 
        Console.WriteLine(vbCrLf & "--- Display information about a constructed type, its")
        Console.WriteLine("    generic type definition, and an ordinary type.")

        ' Create a Dictionary of Test objects, using strings for the 
        ' keys.        
        Dim d As New Dictionary(Of String, Test)()

        DisplayGenericTypeInfo(d.GetType())
        DisplayGenericTypeInfo(d.GetType().GetGenericTypeDefinition())

        ' Display information for an ordinary type.
        DisplayGenericTypeInfo(GetType(String))

    End Sub 'Main
End Class 'Test

' This example produces the following output: 

'--- Display information about a constructed type, its 
'    generic type definition, and an ordinary type. 

'System.Collections.Generic.Dictionary[System.String, Test] 
'        Is this a generic type definition? False 
'        Is it a generic type? True 
'        List type arguments (2): 
'                System.String 
'                Test 

'System.Collections.Generic.Dictionary[TKey,TValue] 
'        Is this a generic type definition? True 
'        Is it a generic type? True 
'        List type arguments (2): 
'                TKey    (unassigned - parameter position 0) 
'                TValue  (unassigned - parameter position 1) 

'System.String 
'        Is this a generic type definition? False 
'        Is it a generic type? False

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show: