bchip
Expert Member
- Joined
- Mar 12, 2013
- Messages
- 1,324
- Reaction score
- 418
Hi
I'm trying to list all the sub-classes automatically but not sure how to do this.
If I had a class Shapes, and within that I have a function that returns all the shapes List<Shapes>
I have to manually add it each time I add a new shape, I was wondering if its possible to do this through reflection somehow,
that it automatically gets all the subclassess and adds it?
Example
class Shapes
public static class AllShapes
public static List<Shapes> getAllShapes()
{
List<aShape> newList= new List<aShape> {}
newlist.add(new Square());
newlist.add(new Rectangle());
//---manually add more here---
return newList;
}
public class Square() : iShape {}
public class Rectange() : iShape {}
public class Circle() : iShape {}
public class Diamond() : iShape {}
I'm trying to list all the sub-classes automatically but not sure how to do this.
If I had a class Shapes, and within that I have a function that returns all the shapes List<Shapes>
I have to manually add it each time I add a new shape, I was wondering if its possible to do this through reflection somehow,
that it automatically gets all the subclassess and adds it?
Example
class Shapes
public static class AllShapes
public static List<Shapes> getAllShapes()
{
List<aShape> newList= new List<aShape> {}
newlist.add(new Square());
newlist.add(new Rectangle());
//---manually add more here---
return newList;
}
public class Square() : iShape {}
public class Rectange() : iShape {}
public class Circle() : iShape {}
public class Diamond() : iShape {}