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

test-220.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 245eb3819670ca3199ecf37506bbd21c7d95a930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// Tests for bug #51446, where MCS did not pick the right enumerator
// from a class.
//

using System;
using System.Collections;
using System.Collections.Specialized;

namespace MonoBUG
{

	public class Bug
	{
		public static int Main(string[] args)
		{
			FooList l = new FooList();
			Foo f1 = new Foo("First");
			Foo f2 = new Foo("Second");

			l.Add(f1);
			l.Add(f2);

			foreach (Foo f in l) {
			}

			if (FooList.foo_current_called != true)
				return 1;
			if (FooList.ienumerator_current_called != false)
				return 2;
			Console.WriteLine ("Test passes");
			return 0;
		}
	}

	public class Foo
	{
		private string m_name;
		
		public Foo(string name)
		{
			m_name = name;
		}
		
		public string Name {
			get { return m_name; }
		}
	}

	[Serializable()]
	public class FooList : DictionaryBase  
	{
		public static bool foo_current_called = false;
		public static bool ienumerator_current_called = false;
			
		public FooList() 
		{
		}
		
		public void Add(Foo value) 
		{
			Dictionary.Add(value.Name, value);
		}
		
		public new FooEnumerator GetEnumerator() 
		{
			return new FooEnumerator(this);
		}
		
		public class FooEnumerator : object, IEnumerator 
		{
			
			private IEnumerator baseEnumerator;
			
			private IEnumerable temp;
			
			public FooEnumerator(FooList mappings) 
			{
				this.temp = (IEnumerable) (mappings);
				this.baseEnumerator = temp.GetEnumerator();
			}
			
			public Foo Current 
			{
				get 
				{
					Console.WriteLine("Foo Current()");
					foo_current_called = true;
					return (Foo) ((DictionaryEntry) (baseEnumerator.Current)).Value;
				}
			}
			
			object IEnumerator.Current 
			{
				get 
				{
					Console.WriteLine("object IEnumerator.Current()");
					ienumerator_current_called = true;
					return baseEnumerator.Current;
				}
			}
			
			public bool MoveNext() 
			{
				return baseEnumerator.MoveNext();
			}
			
			bool IEnumerator.MoveNext() 
			{
				return baseEnumerator.MoveNext();
			}
			
			public void Reset() 
			{
				baseEnumerator.Reset();
			}
			
			void IEnumerator.Reset() 
			{
				baseEnumerator.Reset();
			}
		}
	}
}