Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / Internal / XPathAncestorIterator.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XPathAncestorIterator.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">[....]</owner>
6 //------------------------------------------------------------------------------
7
8 namespace MS.Internal.Xml.XPath {
9     using System;
10     using System.Xml;
11     using System.Xml.XPath;
12     using System.Diagnostics;
13     using System.Globalization;
14
15     internal class XPathAncestorIterator: XPathAxisIterator {
16         public XPathAncestorIterator(XPathNavigator nav, XPathNodeType type, bool matchSelf) : base(nav, type, matchSelf) {}
17         public XPathAncestorIterator(XPathNavigator nav, string name, string namespaceURI, bool matchSelf) : base(nav, name, namespaceURI, matchSelf) {}
18         public XPathAncestorIterator(XPathAncestorIterator other) : base(other) { }
19
20         public override bool MoveNext() {
21             if (first) {
22                 first = false;
23                 if(matchSelf && Matches) {
24                     position = 1;
25                     return true;
26                 }
27             }
28
29             while (nav.MoveToParent()) {
30                 if (Matches) {
31                     position ++;
32                     return true;
33                 }
34             }
35             return false;
36         }
37
38         public override XPathNodeIterator Clone() { return new XPathAncestorIterator(this); }
39     }    
40 }
41