[interp] Reduce computation under calc_section mutex
[mono-project.git] / mcs / tests / test-220.cs
blob245eb3819670ca3199ecf37506bbd21c7d95a930
1 //
2 // Tests for bug #51446, where MCS did not pick the right enumerator
3 // from a class.
4 //
6 using System;
7 using System.Collections;
8 using System.Collections.Specialized;
10 namespace MonoBUG
13 public class Bug
15 public static int Main(string[] args)
17 FooList l = new FooList();
18 Foo f1 = new Foo("First");
19 Foo f2 = new Foo("Second");
21 l.Add(f1);
22 l.Add(f2);
24 foreach (Foo f in l) {
27 if (FooList.foo_current_called != true)
28 return 1;
29 if (FooList.ienumerator_current_called != false)
30 return 2;
31 Console.WriteLine ("Test passes");
32 return 0;
36 public class Foo
38 private string m_name;
40 public Foo(string name)
42 m_name = name;
45 public string Name {
46 get { return m_name; }
50 [Serializable()]
51 public class FooList : DictionaryBase
53 public static bool foo_current_called = false;
54 public static bool ienumerator_current_called = false;
56 public FooList()
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();
83 public Foo Current
85 get
87 Console.WriteLine("Foo Current()");
88 foo_current_called = true;
89 return (Foo) ((DictionaryEntry) (baseEnumerator.Current)).Value;
93 object IEnumerator.Current
95 get
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();
113 public void Reset()
115 baseEnumerator.Reset();
118 void IEnumerator.Reset()
120 baseEnumerator.Reset();