C#C
C#3y ago
Hugh

✅ Getting generic type parameters using reflection

Using the reflection system, how can I get at the generic type parameters?
I have the following:
public class MyClass<T1, T2> {}

Type myClassType = typeof(MyClass<string, int>);
Type myClassGenericType = myClassType.GetGenericTypeDefinition();


And from myClassGenericType, I want to get details of what the generic type parameters are (T1 and T2).

In the debugger, this information is in GenericTypeParameters on RuntimeType, but this isn't part of Type, and RuntimeType is private, so I can't get at its internals.
Was this page helpful?