How can I get similar functionality to doc.Descendants() using linq against a collection of objects that contains sub collections of the same objects X levels deep?
The last nested collection contains the data in need to get at, all the other parent collections are merely groupings. I could transform the collection to an XDocument and call the descendants function but I would prefer to mimic that functionality against this object collection.
public class ProductLine
{
public string Id {get;set;}
public string ParentId {get;set;}
public string Name {get;set;}
public string Type {get;set;}
public string Level {get;set;}
public IEnumerable<ProductLine> Children {get;set;}
}
I can have a list of ProductLine that contains child lists of ProductLine. The nested levels can vary depending on how the data was set up so I never know how many levels there are. The bottom most list will have a Type="Model" while every list prior will have a Type="Series" resulting in something like:
Series1
Series2
Series3
Model1
Model1
Series2
Model3
Model4