I know you can check if all elements from one list exist in another list like this (from another post here):
bool result = list.All(x => dataList.Contains(x));
But how do I check if all elements exist in another list have the same “subvalue”?
I have two xml documents _mapdoc and _mapdocCopy, and I want to compare all <file> elements where the attribute path are all found in the other xml document.
So I started doing something similar to above:
if (_mapdocCopy.Descendants("file").All(x => _mapdoc.Descendants("file").Contains(x)))
But I immediately realized that this would compare the entire <file> elements, and they will often not be the same (they may have different sub elements), even if their “path” attribute have the same values. And it’s only this I want to test for.
I also (in a different context) want to be able to get the one’s that are not the same (still with regards to the path attribute only), so help with that would also be appreciated. But it’s a different question, I still need the Linq query above.
Any ideas?
I’d think along the lines of replacing the
.Containswith.Any(appropriate condition). Something like:Edit: Ad second part, the brute force approach is:
(take those that don’t exist in the other set — note that the closure is negated). However there is also Except linq method. I am not sure I’ve got correct syntax, but it would be something like:
(except where I am not sure whether the closure will convert to IEqualityComparer or needs some extra hackery for it)