using System;
using System.Reflection;
using System.Collections.Generic;
public class Base { }
public class Derived : Base { }
public class Test
{
public static void Main()
{
Type derivedType = typeof(Derived<>);
DisplayGenericTypeInfo(derivedType);
}
private static void DisplayGenericTypeInfo(Type t)
{
Console.WriteLine("\tIs this a generic type definition? {0}", t.IsGenericTypeDefinition);
Console.WriteLine("\tIs it a generic type? {0}", t.IsGenericType);
Console.WriteLine("\tDoes it have unassigned generic parameters? {0}", t.ContainsGenericParameters);
if (t.IsGenericType)
{
Type[] typeArguments = t.GetGenericArguments();
Console.WriteLine("\tList type arguments ({0}):", typeArguments.Length);
foreach (Type tParam in typeArguments)
{
if (tParam.IsGenericParameter)
{
Console.WriteLine(tParam);
Console.WriteLine(tParam.GenericParameterPosition);
}
}
}
}
}