[runtime] Fix Empty generic enumerator equality
[mono.git] / mcs / class / corlib / System / Array.cs
index d699446f2b5ce3aad52382b8900a6bde0a3161bd..91424bc6f8f6dfbf4d2c5457e453f4db01add388 100644 (file)
@@ -68,7 +68,10 @@ namespace System
 
                internal IEnumerator<T> InternalArray__IEnumerable_GetEnumerator<T> ()
                {
-                       return new InternalEnumerator<T> (this);
+                       if (Length == 0)
+                               return EmptyInternalEnumerator<T>.Value;
+                       else
+                               return new InternalEnumerator<T> (this);
                }
 
                internal void InternalArray__ICollection_Clear ()
@@ -271,6 +274,38 @@ namespace System
                        }
                }
 
+               internal class EmptyInternalEnumerator<T> : IEnumerator<T>
+               {
+                       public static readonly EmptyInternalEnumerator<T> Value = new EmptyInternalEnumerator<T> ();
+
+                       public void Dispose ()
+                       {
+                               return;
+                       }
+
+                       public bool MoveNext ()
+                       {
+                               return false;
+                       }
+
+                       public T Current {
+                               get {
+                                       throw new InvalidOperationException ("Enumeration has not started. Call MoveNext");
+                               }
+                       }
+
+                       object IEnumerator.Current {
+                               get {
+                                       return Current;
+                               }
+                       }
+
+                       void IEnumerator.Reset ()
+                       {
+                               return;
+                       }
+               }
+
                // InternalCall Methods
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                extern int GetRank ();