I have several classes that exhibit a inheritance structure:
public class BaseClass
{
Guid ID {get;set;}
}
public class LeafType : BaseClass{ /* omitted */}
public class OtherLeafType : BaseClass{ /* omitted */}
public class Node : BaseClass
{
public List<LeafType> FirstLeaves {get;set;}
public List<OtherLeafType > SecondLeaves {get;set;}
public ???? AllLeaves {get;} //Returns all items in both FirstLeaves and SecondLeaves
}
In the example above, Node
has two collections, whose elements derive from BaseClass
. Does .Net have a collection that can combine these two collections and automatically update when either FirstLeaves
or SecondLeaves
changes? I have found the class System.Windows.Data.CompositeCollection, but it is in PresentationFramework, which to me indicates that it is intended for UI purposes. My class Node
lives in an assembly that has nothing to do with the UI, so CompositeCollection
looks like a bad fit. Is there any other class that would serve a similar purpose?
Update 1: Looking at the answers so far, it seems that my question was not clearly formulated: CompositeCollection
Enables multiple collections and items to be displayed as a single list, but I was wondering if the .Net framework supplies a type with similar functionality that is not related to the GUI. If not, then I will roll my own solution, which looks very much like the answer by @Erik Madsen