I currently have a bunch of config files I need to load into an IOrderedEnumerable My current approach looks like so:
foreach (var item in configFiles)
{
XDocument myxml = XDocument.Load(item);
var items = myxml.Root.Elements("Item");
Items = items.OrderBy(x => x.Attribute("ID").Value);
ItemsLength += Items.Count();
}
The problem is, instead of making Items
equal to items.OrderBy(x => x.Attribute("ID").Value)
I'd like to join that to the end of the currently existing IOrderedEnumerable so I'm not overwriting it each time I load a new XDocument and get all of the elements from it. How would I do this?
EDIT: I know that if I change this ItemsLength += Items.Count();
will no longer function properly. That's something I'll change on my own.
You can do the whole thing declaratively:
This basically finds all the elements, but remembers which configuration each is in.
Alternatively, just create a
List<XElement>
and add each item's contents:In some ways that's less elegant, but it's probably easier to understand :)