© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
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();
public class MyClass<T1, T2> {}

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


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

In the debugger, this information is in
GenericTypeParameters
GenericTypeParameters
on
RuntimeType
RuntimeType
, but this isn't part of
Type
Type
, and
RuntimeType
RuntimeType
is private, so I can't get at its internals.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Getting method parameters with reflection on library code
C#CC# / help
14mo ago
❔ Getting Inherited Generic-Typed Inner Classes With Reflection
C#CC# / help
3y ago
Using pointers as generic a generic type
C#CC# / help
4y ago