Getting a Collection of sublcass objects. Is this possible?

I have a question on C# clases. Lets say I have a base class of type Employee. Then assume I have sublcasses of Employee cales HourlyEmployee, SalariedEmployee, etc. Is there any good way to get like an array or ArrayList that contains one instance of each subclass type without explicitly having to insert them one at a time manually

I would like some recomendations on this if you have any. I hava a situation where I might have to add many sublasses and maintaining the manual entry into something like a colletion would be painful.

Thanks



Answer this question

Getting a Collection of sublcass objects. Is this possible?

  • .Net Nemo

    C# questions should be asked in the C# forums.

    As for the question, I suggest that you enum the classes of a namespace or assembly and build your tree based on the Type::BaseType function. Keep a struct with fields such as name, parent, children, stick that in a Dictionary, with Type::Fullname as the key, and fill it up as you go through the types of the namespace.



  • Hermit Dave

    Or better yet, Is there a way with reflection to get all subclasses of a specific type
  • Getting a Collection of sublcass objects. Is this possible?