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);
DisplayGenericTypeInfo(derivedType.BaseType);
}
private static void DisplayGenericTypeInfo(Type t)
{
Console.WriteLine("\r\n{0}", 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(
"\t\t{0} (unassigned - parameter position {1})",
tParam,
tParam.GenericParameterPosition);
}
else
{
Console.WriteLine("\t\t{0}", tParam);
}
}
}
}
}