1 //------------------------------------------------------------------------------
2 // <copyright file="XPathSingletonIterator.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</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 XPathSingletonIterator: ResetableIterator {
16         private XPathNavigator nav;
17         private int position;
18 
XPathSingletonIterator(XPathNavigator nav)19         public XPathSingletonIterator(XPathNavigator nav) {
20             Debug.Assert(nav != null);
21             this.nav = nav;
22         }
23 
XPathSingletonIterator(XPathNavigator nav, bool moved)24         public XPathSingletonIterator(XPathNavigator nav, bool moved) : this(nav) {
25             if (moved) {
26                 position = 1;
27             }
28         }
29 
XPathSingletonIterator(XPathSingletonIterator it)30         public XPathSingletonIterator(XPathSingletonIterator it) {
31             this.nav      = it.nav.Clone();
32             this.position = it.position;
33         }
34 
Clone()35         public override XPathNodeIterator Clone() {
36             return new XPathSingletonIterator(this);
37         }
38 
39         public override XPathNavigator Current {
40             get { return nav; }
41         }
42 
43         public override int CurrentPosition {
44             get { return position; }
45         }
46 
47         public override int Count {
48             get { return 1; }
49         }
50 
MoveNext()51         public override bool MoveNext() {
52             if(position == 0) {
53                 position = 1;
54                 return true;
55             }
56             return false;
57         }
58 
Reset()59         public override void Reset() {
60             position = 0;
61         }
62     }
63 }
64