At runtime, I would like to specify a parent class, and then the program would generate a list of all children classes (of however many generations). For example, if I had Entity
as a parent, and Item:Entity
and Actor:Entity
, there would be two strings, "Actor" and "Item".
I see that System.Reflection.TypeInfo
is exactly what I am looking for. However, it appears this is exclusive to .NET 4.5, and my environment is unfortunately stuck at 3.5.
Is there an alternative way to do this in .NET 3.5, or should I consider an upgrade?
var pType = typeof(Entity);
IEnumerable<string> children = Enumerable.Range(1, iterations)
.SelectMany(i => Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.IsClass && t != pType
&& pType.IsAssignableFrom(t))
.Select(t => t.Name));
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With