I have a class structure which looks like:
class TestResults {
public bool IsSuccess;
public bool IsFailure;
public IList<TestResults> SubTestResults;
}
So, a test has multiple subtests, and the above captures the results.
I want to find all of the TestResults which have IsFailure
= true.
Starting with:
var failures = from result in results
where result.IsFailure
select result;
This gives me the top level results which have IsFailure=true, but I want to get all of the tests, and subtests, which have IsFailure=true, and have all of these in list. Is there a linq query that can do this, or should I be using old-fashioned loops?
Update: I should say the my usage of these classes means the tree is only 2-deep (structure of the classes is not under my control).
So I have:
Test1 - SubTest11
SubTest12
SubTest13
Test2 - SubTest21
SubTest22
Test3 - SubTest31
SubTest32
SubTest33
SubTest34
I need all those subtests which have IsFailure = true.