System.Xml.Xsl.Runtime.XPathPrecedingMergeIterator.MoveNext C# (CSharp) Method

MoveNext() public method

Position this iterator to the next preceding node in document order. Discard all input nodes that are followed by another input node in the same document. This leaves one node per document from which the complete set of preceding nodes can be derived without possibility of duplicates. Return IteratorResult.NeedInputNode if the next input node needs to be fetched first. Return IteratorResult.HaveCurrent if the Current property is set to the next node in the iteration.
public MoveNext ( XPathNavigator input ) : IteratorResult
input System.Xml.XPath.XPathNavigator
return IteratorResult
        public IteratorResult MoveNext(XPathNavigator input) {
            switch (this.state) {
                case IteratorState.NeedCandidateCurrent:
                    // If there are no more input nodes, then iteration is complete
                    if (input == null)
                        return IteratorResult.NoMoreNodes;

                    // Save input node as current node
                    this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, input);

                    // Scan for additional input nodes within the same document (since they are after navCurrent in docorder)
                    this.state = IteratorState.HaveCandidateCurrent;
                    return IteratorResult.NeedInputNode;

                case IteratorState.HaveCandidateCurrent:
                    // If there are no more input nodes,
                    if (input == null) {
                        // Then candidate node has been selected, and there are no further input nodes
                        this.state = IteratorState.HaveCurrentNoNext;
                    }
                    else {
                        // If the input node is in the same document as the current node,
                        if (this.navCurrent.ComparePosition(input) != XmlNodeOrder.Unknown) {
                            // Then update the current node and get the next input node
                            this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, input);
                            return IteratorResult.NeedInputNode;
                        }

                        // Save the input node as navNext
                        this.navNext = XmlQueryRuntime.SyncToNavigator(this.navNext, input);
                        this.state = IteratorState.HaveCurrentHaveNext;
                    }
                    PushAncestors();
                    break;
            }

            if (!this.navStack.IsEmpty) {
                while (true) {
                    // Move to the next matching node that is before the top node on the stack in document order
                    if (this.filter.MoveToFollowing(this.navCurrent, this.navStack.Peek()))
                        // Found match
                        return IteratorResult.HaveCurrentNode;

                    // Do not include ancestor nodes as part of the preceding axis
                    this.navCurrent.MoveTo(this.navStack.Pop());

                    // No more preceding matches possible
                    if (this.navStack.IsEmpty)
                        break;
                }
            }

            if (this.state == IteratorState.HaveCurrentNoNext) {
                // No more nodes, so iteration is complete
                this.state = IteratorState.NeedCandidateCurrent;
                return IteratorResult.NoMoreNodes;
            }

            // Make next node the current node and start trying to find input node greatest in docorder
            this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, this.navNext);
            this.state = IteratorState.HaveCandidateCurrent;
            return IteratorResult.HaveCurrentNode;
        }
XPathPrecedingMergeIterator