Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is how I would do it to cover a list of Nodes no matter how deep it is:</p> <p>The Node class:</p> <pre><code>public class Node { public Guid Id { get; set; } public DateTime Created { get; set; } public List&lt;Node&gt; Nodes { get; set; } public Node() { this.Nodes = new List&lt;Node&gt;(); } public List&lt;Node&gt; FindNodes(Func&lt;Node, bool&gt; condition) { List&lt;Node&gt; resList = new List&lt;Node&gt;(); if (this.Nodes != null &amp;&amp; this.Nodes.Count &gt; 0) { this.Nodes.ForEach(x =&gt; { resList.AddRange(x.FindNodes(condition)); if (condition(x)) resList.Add(x); } ); } return resList; } } </code></pre> <p>Having this list of Nodes for example:</p> <pre><code>List&lt;Node&gt; nodeList = new List&lt;Node&gt;() { new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 01, 10), Nodes = { new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 01, 11) }, new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 01, 12) } } }, new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 02, 10), Nodes = { new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 02, 11), Nodes = { new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 11, 11) }, new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 12, 12), Nodes = { new Node() { Id = Guid.NewGuid(), Created = new DateTime(2011, 11, 11) }, new Node() { Id = Guid.NewGuid(), Created = new DateTime(2011, 12, 12) } } } } }, new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 02, 12) } } }, new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 03, 10), Nodes = { new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 03, 11) }, new Node() { Id = Guid.NewGuid(), Created = new DateTime(2009, 03, 12) } } }, }; </code></pre> <p>I can find any sub-node I want like that:</p> <pre><code>List&lt;Node&gt; resList = new List&lt;Node&gt;(); nodeList.ForEach(x =&gt; resList.AddRange(x.FindNodes(y =&gt; y.Created.Day == 12))); </code></pre> <p>You can look by anything you want to. In the above example I search for nodes that are Created on the 12th day of any month and year.</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. This table or related slice is empty.
    1. VO
      singulars
      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