cleol
[mcs.git] / tests / gtest-053.cs
blob1feda3b96c47292d8692319215b736c2f14940ee
1 //
2 // Important test: Type parameters and boxing (26.7.3).
3 //
4 // This tests the constrained_ prefix opcode.
5 //
6 using System;
8 public interface ICounter
10 void Increment ();
13 namespace ValueTypeCounters
15 public struct SimpleCounter : ICounter
17 public int Value;
19 public void Increment ()
21 Value += 2;
25 public struct PrintingCounter : ICounter
27 public int Value;
29 public override string ToString ()
31 return Value.ToString ();
34 public void Increment ()
36 Value += 2;
40 public struct ExplicitCounter : ICounter
42 public int Value;
44 public override string ToString ()
46 return Value.ToString ();
49 void ICounter.Increment ()
51 Value++;
55 public struct InterfaceCounter : ICounter
57 public int Value;
59 public override string ToString ()
61 return Value.ToString ();
64 void ICounter.Increment ()
66 Value++;
69 public void Increment ()
71 Value += 2;
76 namespace ReferenceTypeCounters
78 public class SimpleCounter : ICounter
80 public int Value;
82 public void Increment ()
84 Value += 2;
88 public class PrintingCounter : ICounter
90 public int Value;
92 public override string ToString ()
94 return Value.ToString ();
97 public void Increment ()
99 Value += 2;
103 public class ExplicitCounter : ICounter
105 public int Value;
107 public override string ToString ()
109 return Value.ToString ();
112 void ICounter.Increment ()
114 Value++;
118 public class InterfaceCounter : ICounter
120 public int Value;
122 public override string ToString ()
124 return Value.ToString ();
127 void ICounter.Increment ()
129 Value++;
132 public void Increment ()
134 Value += 2;
139 namespace Test
141 using V = ValueTypeCounters;
142 using R = ReferenceTypeCounters;
144 public class Test<T>
145 where T : ICounter
147 public static void Foo (T x)
149 Console.WriteLine (x.ToString ());
150 x.Increment ();
151 Console.WriteLine (x.ToString ());
155 public class X
157 static void Main ()
159 Test<V.SimpleCounter>.Foo (new V.SimpleCounter ());
160 Test<V.PrintingCounter>.Foo (new V.PrintingCounter ());
161 Test<V.ExplicitCounter>.Foo (new V.ExplicitCounter ());
162 Test<V.InterfaceCounter>.Foo (new V.InterfaceCounter ());
163 Test<R.SimpleCounter>.Foo (new R.SimpleCounter ());
164 Test<R.PrintingCounter>.Foo (new R.PrintingCounter ());
165 Test<R.ExplicitCounter>.Foo (new R.ExplicitCounter ());
166 Test<R.InterfaceCounter>.Foo (new R.InterfaceCounter ());