Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / Internal / XPathSelectionIterator.cs
blobdeb898114557bd638df9a96731834c9688d3a727
1 //------------------------------------------------------------------------------
2 // <copyright file="XPathSelectionIterator.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
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;
15 // We need this wrapper object to:
16 // 1. Calculate position
17 // 2. Protect internal query.Current from user who may call MoveNext().
18 internal class XPathSelectionIterator : ResetableIterator {
19 private XPathNavigator nav;
20 private Query query;
21 private int position;
23 internal XPathSelectionIterator(XPathNavigator nav, Query query) {
24 this.nav = nav.Clone();
25 this.query = query;
28 protected XPathSelectionIterator(XPathSelectionIterator it) {
29 this.nav = it.nav.Clone();
30 this.query = (Query) it.query.Clone();
31 this.position = it.position;
34 public override void Reset() {
35 this.query.Reset();
38 public override bool MoveNext() {
39 XPathNavigator n = query.Advance();
40 if( n != null ) {
41 position++;
42 if (!nav.MoveTo(n)) {
43 nav = n.Clone();
45 return true;
47 return false;
50 public override int Count { get { return query.Count; } }
51 public override XPathNavigator Current { get { return nav; } }
52 public override int CurrentPosition { get { return position; } }
53 public override XPathNodeIterator Clone() { return new XPathSelectionIterator(this); }