I have a source list like this:
class Foo {
public int ID;
public List<Foo> Children;
}
// Then somewhere else...
Foo root = new Foo(); // The Children is a nested list
Then I have a new type that I have access to make changes to:
class Bar : Foo {
public string Name;
}
What I'd like to do is create a new Bar that is a replica of the root variable above, however has a value for the Name property in each item. It can be a default value for this example.
I've tried LINQ's Select(...) off the Children of the root but I can't get the syntax down, if that's even the correct route.
I have this so far, which only works on the first level of child items in the root list. I'd need it to go through all levels of children.
Bar = new ObservableCollection<Bar>(root.Children.Select(c => new Bar { Name = "Foo" }));