views:

305

answers:

2

I have the following structure

public class MyClass : MyBaseClass<System.Int32>
{
}

In a static method and without instantiating a new MyClass instance how do I get the type of the generic parameter used to build the concrete base class? e.g in the above example System.Int32

A: 
Type arg = typeof(MyClass).BaseType.GetGenericArguments()[0];
Darin Dimitrov
+3  A: 

Try this

public static Type GetBaseTypeGenericArgument(Type type) {
  return type.BaseType.GetGenericArguments()[0];
}

...
GetBaseTypeGenericArgument(typeof(MyClass));
JaredPar