mscorlib(4.0.0.0) API with additions
XPathNodeIterator.cs
1 using System.Collections;
2 using System.Diagnostics;
3 using System.Text;
4 
5 namespace System.Xml.XPath
6 {
8  [DebuggerDisplay("Position={CurrentPosition}, Current={debuggerDisplayProxy}")]
9  public abstract class XPathNodeIterator : ICloneable, IEnumerable
10  {
11  private class Enumerator : IEnumerator
12  {
13  private XPathNodeIterator original;
14 
15  private XPathNodeIterator current;
16 
17  private bool iterationStarted;
18 
19  public virtual object Current
20  {
21  get
22  {
23  if (iterationStarted)
24  {
25  if (current == null)
26  {
27  throw new InvalidOperationException(Res.GetString("Sch_EnumFinished", string.Empty));
28  }
29  return current.Current.Clone();
30  }
31  throw new InvalidOperationException(Res.GetString("Sch_EnumNotStarted", string.Empty));
32  }
33  }
34 
35  public Enumerator(XPathNodeIterator original)
36  {
37  this.original = original.Clone();
38  }
39 
40  public virtual bool MoveNext()
41  {
42  if (!iterationStarted)
43  {
44  current = original.Clone();
45  iterationStarted = true;
46  }
47  if (current == null || !current.MoveNext())
48  {
49  current = null;
50  return false;
51  }
52  return true;
53  }
54 
55  public virtual void Reset()
56  {
57  iterationStarted = false;
58  }
59  }
60 
61  private struct DebuggerDisplayProxy
62  {
63  private XPathNodeIterator nodeIterator;
64 
65  public DebuggerDisplayProxy(XPathNodeIterator nodeIterator)
66  {
67  this.nodeIterator = nodeIterator;
68  }
69 
70  public override string ToString()
71  {
72  StringBuilder stringBuilder = new StringBuilder();
73  stringBuilder.Append("Position=");
74  stringBuilder.Append(nodeIterator.CurrentPosition);
75  stringBuilder.Append(", Current=");
76  if (nodeIterator.Current == null)
77  {
78  stringBuilder.Append("null");
79  }
80  else
81  {
82  stringBuilder.Append('{');
83  stringBuilder.Append(new XPathNavigator.DebuggerDisplayProxy(nodeIterator.Current).ToString());
84  stringBuilder.Append('}');
85  }
86  return stringBuilder.ToString();
87  }
88  }
89 
90  internal int count = -1;
91 
94  public abstract XPathNavigator Current
95  {
96  get;
97  }
98 
101  public abstract int CurrentPosition
102  {
103  get;
104  }
105 
108  public virtual int Count
109  {
110  get
111  {
112  if (count == -1)
113  {
114  XPathNodeIterator xPathNodeIterator = Clone();
115  while (xPathNodeIterator.MoveNext())
116  {
117  }
118  count = xPathNodeIterator.CurrentPosition;
119  }
120  return count;
121  }
122  }
123 
124  private object debuggerDisplayProxy
125  {
126  get
127  {
128  if (Current != null)
129  {
131  }
132  return null;
133  }
134  }
135 
138  object ICloneable.Clone()
139  {
140  return Clone();
141  }
142 
145  public abstract XPathNodeIterator Clone();
146 
150  public abstract bool MoveNext();
151 
154  public virtual IEnumerator GetEnumerator()
155  {
156  return new Enumerator(this);
157  }
158  }
159 }
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
abstract int CurrentPosition
When overridden in a derived class, gets the index of the current position in the selected set of nod...
Definition: __Canon.cs:3
virtual int Count
Gets the index of the last node in the selected set of nodes.
virtual IEnumerator GetEnumerator()
Returns an T:System.Collections.IEnumerator object to iterate through the selected node set.
abstract bool MoveNext()
When overridden in a derived class, moves the T:System.Xml.XPath.XPathNavigator object returned by th...
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
Provides an iterator over a selected set of nodes.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition: ICloneable.cs:7
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
abstract XPathNavigator Current
When overridden in a derived class, gets the T:System.Xml.XPath.XPathNavigator object for this T:Syst...
Provides a cursor model for navigating and editing XML data.
The exception that is thrown when a method call is invalid for the object's current state.
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9