C# TypeInfo GetGenericTypeDefinition
Description
TypeInfo GetGenericTypeDefinition
Returns a Type object
that represents a generic type definition from which the current generic
type can be constructed.
Syntax
TypeInfo.GetGenericTypeDefinition
has the following syntax.
public virtual Type GetGenericTypeDefinition()
Returns
TypeInfo.GetGenericTypeDefinition
method returns A Type object representing a generic type from which the current type can
be constructed.
Example
/*from w ww.j a va2 s. c om*/
using System;
using System.Reflection;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Dictionary<string, Test> d = new Dictionary<string, Test>();
Type constructed = d.GetType();
DisplayTypeInfo(constructed);
Type generic = constructed.GetGenericTypeDefinition();
DisplayTypeInfo(generic);
}
private static void DisplayTypeInfo(Type t)
{
Console.WriteLine(t.IsGenericTypeDefinition);
Console.WriteLine(t.IsGenericType);
Type[] typeArguments = t.GetGenericArguments();
Console.WriteLine(typeArguments.Length);
foreach (Type tParam in typeArguments)
{
Console.WriteLine("\t\t{0}", tParam);
}
}
}
The code above generates the following result.