2 // System.Xml.XmlNodeList
5 // Kral Ferch <kral_ferch@hotmail.com>
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
36 internal class XmlNodeListChildren : XmlNodeList
40 private class Enumerator : IEnumerator
42 IHasXmlChildNode parent;
43 XmlLinkedNode currentChild;
46 internal Enumerator (IHasXmlChildNode parent)
50 passedLastNode = false;
53 public virtual object Current {
55 if ((currentChild == null) ||
56 (parent.LastLinkedChild == null) ||
57 (passedLastNode == true))
58 throw new InvalidOperationException();
64 public virtual bool MoveNext()
66 bool movedNext = true;
68 if (parent.LastLinkedChild == null) {
71 else if (currentChild == null) {
72 currentChild = parent.LastLinkedChild.NextLinkedSibling;
75 if (Object.ReferenceEquals(currentChild, parent.LastLinkedChild)) {
77 passedLastNode = true;
80 currentChild = currentChild.NextLinkedSibling;
87 public virtual void Reset()
97 IHasXmlChildNode parent;
102 public XmlNodeListChildren(IHasXmlChildNode parent)
104 this.parent = parent;
111 public override int Count {
115 if (parent.LastLinkedChild != null) {
116 XmlLinkedNode currentChild = parent.LastLinkedChild.NextLinkedSibling;
119 while (!Object.ReferenceEquals(currentChild, parent.LastLinkedChild)) {
120 currentChild = currentChild.NextLinkedSibling;
133 public override IEnumerator GetEnumerator ()
135 return new Enumerator(parent);
138 public override XmlNode Item (int index)
140 XmlNode requestedNode = null;
142 // Return null if index is out of range. by DOM design.
146 // Instead of checking for && index < Count which has to walk
147 // the whole list to get a count, we'll just keep a count since
148 // we have to walk the list anyways to get to index.
149 if ((index >= 0) && (parent.LastLinkedChild != null)) {
150 XmlLinkedNode currentChild = parent.LastLinkedChild.NextLinkedSibling;
153 while ((count < index) && !Object.ReferenceEquals(currentChild, parent.LastLinkedChild))
155 currentChild = currentChild.NextLinkedSibling;
159 if (count == index) {
160 requestedNode = currentChild;
164 return requestedNode;