C
C#2y ago
Tvde1

Use reflection to get type of abstract base class [Answered]

I have the following setup:
abstract class Formatter<T> { }
class StringFormatter : Formatter<string> { }
abstract class Formatter<T> { }
class StringFormatter : Formatter<string> { }
I want to use reflection to find out what kind of formatter a certain type is
Type type = typeof(StringFormatter);
string typeName = ??? // should be "string"
Type type = typeof(StringFormatter);
string typeName = ??? // should be "string"
How do I go about getting this?
4 Replies
Tvde1
Tvde12y ago
Btw there is no reflection tag Maybe Type.GetTypeInheritance() is a good place to start?
Tvde1
Tvde12y ago
Thanks!
Accord
Accord2y ago
✅ This post has been marked as answered!