Revert previous XPath fix. Fix is rather needed in XPathNodeIterator.GetEnumerator().
[mono.git] / mcs / class / System.XML / System.Xml.XPath / XPathNodeIterator.cs
index 860051ccff92a7a45e5082cd8768ab365bb725ae..5472bd5313f5e06c6b807ce3b3b8ac7730aa7d75 100644 (file)
@@ -88,13 +88,40 @@ namespace System.Xml.XPath
 #if NET_2_0
                public virtual IEnumerator GetEnumerator ()
                {
-                       while (MoveNext ())
-                               yield return Current;
+                       return new XPathNodeIteratorEnumerator (this);
                }
 #endif
 
                public abstract bool MoveNext ();
                
                #endregion
+
+               struct XPathNodeIteratorEnumerator : IEnumerator
+               {
+                       XPathNodeIterator source;
+                       XPathNavigator current;
+                       public XPathNodeIteratorEnumerator (XPathNodeIterator source)
+                       {
+                               this.source = source.Clone ();
+                               current = null;
+                       }
+
+                       public bool MoveNext ()
+                       {
+                               if (!source.MoveNext ())
+                                       return false;
+                               current = source.Current.Clone ();
+                               return true;
+                       }
+                       
+                       public object Current {
+                               get { return current; }
+                       }
+
+                       public void Reset ()
+                       {
+                               throw new NotSupportedException ();
+                       }
+               }
        }
 }