title: Finding all ancestors until node id
body: <p>I have a Node Tree i like to iterate to find all ancestors until a given point (node) in the tree.
  That way i can inserted/save it back to my db.
  So far i have something like the following which has been proven very useful, so far: </p>
  
  <pre><code>public IEnumerable&lt;INode&gt; Ancestors()
  {
     var parent = this.Parent;
     while (parent != null)
     {
        yield return parent;
        parent = parent.Parent;
     }
  }
  </code></pre>
  
  <p>I think, I should be passing a Func or Func in order to stop/break the sequence.</p>
  
  <p>What would it be the best implementation?.Ta</p>
  
  <p>Edited: Given the answers below. Im thinking going for something more performant like:</p>
  
  <pre><code> public IEnumerable&lt;INode&gt; Ancestors(Func&lt;INode, bool&gt; predicate)
   {
      var parent = this.Parent;
      while (parent != null)
      {
        if (predicate(parent))
        { 
           yield return parent;
        }
        else
        { 
           yield break; 
        }
  
        parent = parent.Parent;
      }
   }
  </code></pre>
  
  <p>Am i right saying Jon's answer will create 2 enumerators?</p>