Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>if it is only two levels (i.e. subtests can't have subtests) then you can do this:</p> <pre><code>var failures = results.Union(results.SelectMany(r =&gt; r.SubTestResults)) .Where(r =&gt; r.IsFailure); </code></pre> <p>This takes the list of results and unions it with the list of all the results children.</p> <p>if you can have an arbitrary depth of subtests then you will need something more complicated, so we first define a helper function for the recursion.</p> <pre><code>IEnumerable&lt;TestResults&gt; AllResults(IEnumerable&lt;TestResults&gt; results) { foreach(var tr in results) { yield return tr; foreach(var sr in AllResults(tr.SubTests)) yield return sr; } } </code></pre> <p>now we use it and do our filter</p> <pre><code>var failures = from result in AllResults(results) where result.IsFailure select results; </code></pre> <p>this should do the trick. however my implementation of AllResults above is not particularly efficient (see <a href="http://blogs.msdn.com/b/wesdyer/archive/2007/03/23/all-about-iterators.aspx" rel="nofollow noreferrer">Wes Dyers blog for details</a>) so you really would want to do the typical recursive to iterative conversion on AllResults.</p> <pre><code>IEnumerable&lt;TestResults&gt; AllResults(IEnumerable&lt;TestResults&gt; results) { var queued = new Queue&lt;TestResult&gt;(results); while(queued.Count &gt; 0) { var tr = queued.Dequeue(); yield return tr; foreach(var sr in tr.SubTests) queued.Enqueue(sr); } } </code></pre> <p>note that you still should add various null checks for completeness</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload