I have a collection containing planets and their moons as a Children collection.
It is a collection but it really represents a tree-like structure. I am showing only 2 tree levels for simplicity but each planet or moon could further have a collection of chemical elements, so I use 2 level tree only for simplicity.
Mercury
Venus
Mars
- Deimos
- Phobos
Jupiter
- Europa
- Ganymede
- Io
I know how to convert this collection to a list, I just use
var myList = myCollection.Values.ToList();
I would like to search this list for each item containing "m" in its name. If parent does not have "m" in its name but any of its children moons has, I would like to include that child (moon) AND its parent (planet). In case of Jupiter, I would include both Jupiter and Ganymede in my list.
My search for "m" would therefore return following list
{Mercury, Mars, Deimos, Jupiter, Ganymede}
Id prefer using lambda for this but it is not required to do so
UPDATE: Structure
BodyNode
-ID [Guid]
-Name [string]
-IsChild [bool]
-Parent [BodyNode]
-Children[BodyList ObservableCollection of BodyNode]
BodyTreeNode : BodyNode
-Expanded [bool]
-Selected [bool]
-Enabled [bool]