blob: 375f9c645bcf03bc5e5bef9d156f172344e27bad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
//------------------------------------------------------------------------------
// <copyright file="XPathNodeList.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Xml {
using System.Xml.XPath;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
internal class XPathNodeList: XmlNodeList {
List<XmlNode> list;
XPathNodeIterator nodeIterator;
bool done;
public XPathNodeList(XPathNodeIterator nodeIterator) {
this.nodeIterator = nodeIterator;
this.list = new List<XmlNode>();
this.done = false;
}
public override int Count {
get {
if (! done) {
ReadUntil(Int32.MaxValue);
}
return list.Count;
}
}
private static readonly object[] nullparams = {};
private XmlNode GetNode(XPathNavigator n) {
IHasXmlNode iHasNode = (IHasXmlNode) n;
return iHasNode.GetNode();
}
internal int ReadUntil(int index) {
int count = list.Count;
while (! done && count <= index) {
if (nodeIterator.MoveNext()) {
XmlNode n = GetNode(nodeIterator.Current);
if (n != null) {
list.Add(n);
count++;
}
} else {
done = true;
break;
}
}
return count;
}
public override XmlNode Item(int index) {
if (list.Count <= index) {
ReadUntil(index);
}
if (index < 0 || list.Count <= index) {
return null;
}
return list[index];
}
public override IEnumerator GetEnumerator() {
return new XmlNodeListEnumerator(this);
}
}
internal class XmlNodeListEnumerator : IEnumerator {
XPathNodeList list;
int index;
bool valid;
public XmlNodeListEnumerator(XPathNodeList list) {
this.list = list;
this.index = -1;
this.valid = false;
}
public void Reset() {
index = -1;
}
public bool MoveNext() {
index++;
int count = list.ReadUntil(index + 1); // read past for delete-node case
if (count - 1 < index) {
return false;
}
valid = (list[index] != null);
return valid;
}
public object Current {
get {
if (valid) {
return list[index];
}
return null;
}
}
}
}
|