1

I have tried to browse through the list of similar questions here, but unfortunately I haven't got the answer I am looking for.

The question I have is quiet simple. Using DotNet, is there a way to get a list of the concrete classes which are derived from an abstract class in C# ?

For example: An abstract class is called Animal. And it has 3 concrete classes derived from it, which are dog, cat and bird.

I would like to get the list of the concrete classes of this Animal abstract class, which will give me the string of the concrete classes name, i.e. dog, cat and bird.

Is there a way to do this in C#?

Rob
  • 26,989
  • 16
  • 82
  • 98
Zan
  • 207
  • 1
  • 9
  • You can scan through all loaded assemblies and find *all* classes which are inherited from your abstract class. Then you can just take its names. *All* means "all which you have implemented yourself or which are loaded (referenced in your project). – Yeldar Kurmangaliyev Jul 19 '17 at 03:53
  • It is called Reflection and it allows you to do pretty much everything with the type system, including construction of new classes (sic) in run time. Reflection is fun, but it is usually advised not to use it, since the need of that is often considered a red flag of poor design decisions were made. Just saying. – jungle_mole Jul 19 '17 at 04:07

0 Answers0