2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / tests / generic-box.2.cs
blob0bea4ab1cf805a5074b80efc2a3968eeaee5ac91
1 using System.Collections.Generic;
2 using UnboxTest;
3 using BoxTest;
5 public class ClassA {}
7 public struct GenStruct<T> {
8 T t;
9 int field;
11 public GenStruct (T _t, int _field) {
12 t = _t;
13 field = _field;
16 public bool isEqualTo (GenStruct<T> gs) {
17 EqualityComparer<T> comp = EqualityComparer<T>.Default;
19 return comp.Equals(gs.t, t) && gs.field == field;
23 public class GenClass<T> {
24 public object boxStruct (GenStruct<T> gs) {
25 return (object)gs;
29 public object boxNullableStruct (GenStruct<T>? gs) {
30 return (object)gs;
35 public class main {
36 public static int Main () {
37 GenClass<int> gci = new GenClass<int> ();
38 GenStruct<int> gsi = new GenStruct<int> (123, 456);
40 if (!gsi.isEqualTo ((GenStruct<int>)gci.boxStruct (gsi)))
41 return 1;
43 if (!gsi.isEqualTo ((GenStruct<int>)gci.boxNullableStruct (gsi)))
44 return 1;
45 if (gci.boxNullableStruct (null) != null)
46 return 1;
49 GenClass<ClassA> gca = new GenClass<ClassA> ();
50 GenStruct<ClassA> gsa = new GenStruct<ClassA> (new ClassA (), 789);
52 if (!gsa.isEqualTo ((GenStruct<ClassA>)gca.boxStruct (gsa)))
53 return 1;
55 if (!gsa.isEqualTo ((GenStruct<ClassA>)gca.boxNullableStruct (gsa)))
56 return 1;
57 if (gca.boxNullableStruct (null) != null)
58 return 1;
61 UnboxerStruct<ClassA> us;
62 Boxer<ClassA> b = new Boxer<ClassA> ();
64 us.field = 123;
66 if (((UnboxerStruct<ClassA>?)b.boxNullable (us)).Value.field != 123)
67 return 1;
68 if (b.boxNullable (null) != null)
69 return 1;
71 return 0;