Jo Shields 3c1f479b9d Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
2015-04-07 09:35:12 +01:00

58 lines
1.9 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="XPathDescendantIterator.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------
namespace MS.Internal.Xml.XPath {
using System.Xml.XPath;
internal class XPathDescendantIterator: XPathAxisIterator {
private int level = 0;
public XPathDescendantIterator(XPathNavigator nav, XPathNodeType type, bool matchSelf) : base(nav, type, matchSelf) {}
public XPathDescendantIterator(XPathNavigator nav, string name, string namespaceURI, bool matchSelf) : base(nav, name, namespaceURI, matchSelf) {}
public XPathDescendantIterator(XPathDescendantIterator it) : base(it) {
this.level = it.level;
}
public override XPathNodeIterator Clone() {
return new XPathDescendantIterator(this);
}
public override bool MoveNext() {
if (first) {
first = false;
if (matchSelf && Matches) {
position = 1;
return true;
}
}
while (true) {
if (nav.MoveToFirstChild()) {
level++;
} else {
while (true) {
if (level == 0) {
return false;
}
if (nav.MoveToNext()) {
break;
}
nav.MoveToParent();
level--;
}
}
if (Matches) {
position++;
return true;
}
}
}
}
}