2 // System.Xml.XmlNodeList
5 // Kral Ferch <kral_ferch@hotmail.com>
11 using System.Collections;
15 public class XmlNodeListChildren : XmlNodeList
19 private class Enumerator : IEnumerator
22 XmlLinkedNode currentChild;
25 internal Enumerator (XmlNode parent)
29 passedLastNode = false;
32 public virtual object Current {
34 if ((currentChild == null) ||
35 (parent.LastLinkedChild == null) ||
36 (passedLastNode == true))
37 throw new InvalidOperationException();
43 public virtual bool MoveNext()
45 bool movedNext = true;
47 if (parent.LastLinkedChild == null) {
50 else if (currentChild == null) {
51 currentChild = parent.LastLinkedChild.NextLinkedSibling;
54 if (Object.ReferenceEquals(currentChild, parent.LastLinkedChild)) {
56 passedLastNode = true;
59 currentChild = currentChild.NextLinkedSibling;
66 public virtual void Reset()
81 public XmlNodeListChildren(XmlNode parent)
90 public override int Count {
94 if (parent.LastLinkedChild != null) {
95 XmlLinkedNode currentChild = parent.LastLinkedChild.NextLinkedSibling;
98 while (!Object.ReferenceEquals(currentChild, parent.LastLinkedChild)) {
99 currentChild = currentChild.NextLinkedSibling;
112 public override IEnumerator GetEnumerator ()
114 return new Enumerator(parent);
117 public override XmlNode Item (int index)
119 XmlNode requestedNode = null;
121 // Instead of checking for && index < Count which has to walk
122 // the whole list to get a count, we'll just keep a count since
123 // we have to walk the list anyways to get to index.
124 if ((index >= 0) && (parent.LastLinkedChild != null)) {
125 XmlLinkedNode currentChild = parent.LastLinkedChild.NextLinkedSibling;
128 while ((count < index) && !Object.ReferenceEquals(currentChild, parent.LastLinkedChild))
130 currentChild = currentChild.NextLinkedSibling;
134 if (count == index) {
135 requestedNode = currentChild;
139 return requestedNode;