Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / Internal / XPathArrayIterator.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XPathArrayIterator.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 using System;
9 using System.Collections;
10 using System.Diagnostics;
11 using System.Text;
12 using System.Xml;
13 using System.Xml.XPath;
14
15 namespace MS.Internal.Xml.XPath {
16
17     [DebuggerDisplay("Position={CurrentPosition}, Current={debuggerDisplayProxy, nq}")]
18     internal class XPathArrayIterator : ResetableIterator {
19         protected IList     list;
20         protected int       index;
21
22         public XPathArrayIterator(IList list) {
23             this.list = list;
24         }
25
26         public XPathArrayIterator(XPathArrayIterator it) {
27             this.list = it.list;
28             this.index = it.index;
29         }
30
31         public XPathArrayIterator(XPathNodeIterator nodeIterator) {
32             this.list = new ArrayList();
33             while (nodeIterator.MoveNext()) {
34                 this.list.Add(nodeIterator.Current.Clone());
35             }
36         }
37
38         public IList AsList {
39             get { return this.list; }
40         }
41
42         public override XPathNodeIterator Clone() {
43             return new XPathArrayIterator(this);
44         }
45
46         public override XPathNavigator Current {
47             get {
48                 Debug.Assert(index <= list.Count);
49
50                 if (index < 1) {
51                     throw new InvalidOperationException(Res.GetString(Res.Sch_EnumNotStarted, string.Empty));
52                 }
53                 return (XPathNavigator) list[index - 1];
54             }
55         }
56
57         public override int CurrentPosition { get { return index; } }
58         public override int Count           { get { return list.Count; } }
59
60         public override bool MoveNext() {
61             Debug.Assert(index <= list.Count);
62             if (index == list.Count) {
63                 return false;
64             }
65             index++;
66             return true;
67         }
68
69         public override void Reset() {
70             index = 0;
71         }
72
73         public override IEnumerator GetEnumerator() {
74             return list.GetEnumerator();
75         }
76
77         private object debuggerDisplayProxy { get { return index < 1 ? null : (object)new XPathNavigator.DebuggerDisplayProxy(Current); } }
78     }
79 }