1
Vote

NodeEnumerator error...

description

Hi,
 
There is a bug in the way you have implemented the NodeEnumerator.MoveNext...
 
It is the method Node.NextNode(...) ....
 
This way the enumaration contains ALL the nodes after the current node... if it is the first node of the tree, it can return the full tree even the nodes at the same level !
 
Please, can you post a bug fix ?
 
Thanks

comments

krys wrote Jun 18, 2007 at 11:56 AM

I have do a correction like this, there is a new method 'NextNode' that has an addition 'parentNode' parameter. I use this method in NodeEnumerator.MoveNext instead of previous one. It allow to stop to get nodes when we have reach the parent node.

I suppose that some other fix should be done in others methods...
    public static Node NextNode(Node current, Node parentNode)      {           if (current != null)            {               if (current.ChildCount > 0)                 return current.FirstChild;              if (current.NextSibling != null)                    return current.NextSibling;             else                {                   do                  {                       current = current.Parent;

                    // We have reach the parent node, do not continue                       if (current == parentNode)                          return null;                    }                   while (current != null && current.NextSibling == null);                 if (current != null)                        current = current.NextSibling;              }           }           return current;     }

krys wrote Jun 18, 2007 at 12:04 PM

Or.... you can add the following at the end of the MoveNext method... ;-)
        //---- Check that we have not reach the same level          // It mean it remain no node to return.         if (Node.GetNodeLevel(FCurrent) == Node.GetNodeLevel(FParent))          {               FCurrent = null;                return false;           }

wrote Feb 12, 2013 at 11:34 PM