2 // Tests for bug #51446, where MCS did not pick the right enumerator
7 using System
.Collections
;
8 using System
.Collections
.Specialized
;
15 public static int Main(string[] args
)
17 FooList l
= new FooList();
18 Foo f1
= new Foo("First");
19 Foo f2
= new Foo("Second");
24 foreach (Foo f
in l
) {
27 if (FooList
.foo_current_called
!= true)
29 if (FooList
.ienumerator_current_called
!= false)
31 Console
.WriteLine ("Test passes");
38 private string m_name
;
40 public Foo(string name
)
46 get { return m_name; }
51 public class FooList
: DictionaryBase
53 public static bool foo_current_called
= false;
54 public static bool ienumerator_current_called
= false;
60 public void Add(Foo
value)
62 Dictionary
.Add(value.Name
, value);
65 public new FooEnumerator
GetEnumerator()
67 return new FooEnumerator(this);
70 public class FooEnumerator
: object, IEnumerator
73 private IEnumerator baseEnumerator
;
75 private IEnumerable temp
;
77 public FooEnumerator(FooList mappings
)
79 this.temp
= (IEnumerable
) (mappings
);
80 this.baseEnumerator
= temp
.GetEnumerator();
87 Console
.WriteLine("Foo Current()");
88 foo_current_called
= true;
89 return (Foo
) ((DictionaryEntry
) (baseEnumerator
.Current
)).Value
;
93 object IEnumerator
.Current
97 Console
.WriteLine("object IEnumerator.Current()");
98 ienumerator_current_called
= true;
99 return baseEnumerator
.Current
;
103 public bool MoveNext()
105 return baseEnumerator
.MoveNext();
108 bool IEnumerator
.MoveNext()
110 return baseEnumerator
.MoveNext();
115 baseEnumerator
.Reset();
118 void IEnumerator
.Reset()
120 baseEnumerator
.Reset();