Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / Internal / XPathSelectionIterator.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XPathSelectionIterator.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     // 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;
22
23         internal XPathSelectionIterator(XPathNavigator nav, Query query) {
24             this.nav = nav.Clone();
25             this.query = query;
26         }
27
28         protected XPathSelectionIterator(XPathSelectionIterator it) {
29             this.nav   = it.nav.Clone();
30             this.query = (Query) it.query.Clone();
31             this.position = it.position;
32         }
33
34         public override void Reset() {
35             this.query.Reset();
36         }
37
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();
44                 }
45                 return true;
46             }
47             return false;
48         }
49
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); }
54     }
55 }