5 // Copyright 2007 Novell (http://www.novell.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
31 using System.Collections.Generic;
36 using XPI = System.Xml.Linq.XProcessingInstruction;
39 namespace System.Xml.Linq
43 internal class XFilterIterator <T> : IEnumerable <T>
45 IEnumerable <object> source;
48 public XFilterIterator (IEnumerable <object> source, XName name)
54 public IEnumerator <T> GetEnumerator ()
56 foreach (object o in source) {
61 if (((XElement) o).Name != name)
64 else if (o is XAttribute) {
65 if (((XAttribute) o).Name != name)
73 IEnumerator IEnumerable.GetEnumerator ()
75 return GetEnumerator ();
79 internal class XDescendantIterator <T> : IEnumerable <T>
81 IEnumerable <T> source;
83 public XDescendantIterator (IEnumerable <object> source)
85 this.source = new XFilterIterator <T> (source, null);
88 public IEnumerator <T> GetEnumerator ()
90 foreach (T t1 in source) {
92 XContainer xc = t1 as XContainer;
93 if (xc == null || xc.FirstChild == null)
95 foreach (T t2 in new XDescendantIterator <T> (xc.Content ()))
100 IEnumerator IEnumerable.GetEnumerator ()
102 return GetEnumerator ();
108 internal class XChildrenIterator : IEnumerable <object>
113 public XChildrenIterator (XContainer source)
115 this.source = source;
118 public IEnumerator <object> GetEnumerator ()
121 n = source.FirstNode;
128 } while (n != source.LastNode);
131 IEnumerator IEnumerable.GetEnumerator ()
133 return GetEnumerator ();