Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mcs/class/corlib/System/Array.cs37
-rw-r--r--mcs/class/corlib/Test/System/ArrayTest.cs14
2 files changed, 50 insertions, 1 deletions
diff --git a/mcs/class/corlib/System/Array.cs b/mcs/class/corlib/System/Array.cs
index d699446f2b5..91424bc6f8f 100644
--- a/mcs/class/corlib/System/Array.cs
+++ b/mcs/class/corlib/System/Array.cs
@@ -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 ();
diff --git a/mcs/class/corlib/Test/System/ArrayTest.cs b/mcs/class/corlib/Test/System/ArrayTest.cs
index 0a04041aea3..36db33d6352 100644
--- a/mcs/class/corlib/Test/System/ArrayTest.cs
+++ b/mcs/class/corlib/Test/System/ArrayTest.cs
@@ -3693,6 +3693,20 @@ public class ArrayTest
Assert.AreEqual (3, c.Counter);
}
+ [Test]
+ public void EnumeratorsEquality ()
+ {
+ int [] normalBase = new int [0];
+ IEnumerable<int> specialBase = new int [0];
+
+ var firstSpecial = specialBase.GetEnumerator ();
+ var secondSpecial = specialBase.GetEnumerator ();
+ var firstNormal = normalBase.GetEnumerator ();
+ var secondNormal = normalBase.GetEnumerator ();
+
+ Assert.IsFalse (object.ReferenceEquals (firstNormal, secondNormal));
+ Assert.IsTrue (object.ReferenceEquals (firstSpecial, secondSpecial));
+ }
[Test]
public void JaggedArrayCtor ()