Reputation: 2165
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
Upvotes: 1
Views: 747
Reputation: 754515
Try this
public static Type GetBaseTypeGenericArgument(Type type) {
return type.BaseType.GetGenericArguments()[0];
}
...
GetBaseTypeGenericArgument(typeof(MyClass));
Upvotes: 5
Reputation: 1038710
Type arg = typeof(MyClass).BaseType.GetGenericArguments()[0];
Upvotes: 0