2006-01-25 Massimiliano Mantione <massi@ximian.com>
[mono.git] / mono / mini / generics.2.cs
1 using System;
2
3 class Tests {
4
5         struct TestStruct {
6                 public int i;
7
8                 public TestStruct (int i) {
9                         this.i = i;
10                 }
11         }
12
13         static int Main ()
14         {
15                 return TestDriver.RunTests (typeof (Tests));
16         }
17
18         public static int test_1_nullable_unbox ()
19         {
20                 return Unbox<int?> (1).Value;
21         }
22
23         public static int test_1_nullable_unbox_null ()
24         {
25                 return Unbox<int?> (null).HasValue ? 0 : 1;
26         }
27
28         public static int test_1_nullable_box ()
29         {
30                 return (int) Box<int?> (1);
31         }
32
33         public static int test_1_nullable_box_null ()
34         {
35                 return Box<int?> (null) == null ? 1 : 0;
36         }
37
38         public static int test_1_isinst_nullable ()
39         {
40                 object o = 1;
41                 return (o is int?) ? 1 : 0;
42         }
43
44         public static int test_1_nullable_unbox_vtype ()
45         {
46                 return Unbox<TestStruct?> (new TestStruct (1)).Value.i;
47         }
48
49         public static int test_1_nullable_unbox_null_vtype ()
50         {
51                 return Unbox<TestStruct?> (null).HasValue ? 0 : 1;
52         }
53
54         public static int test_1_nullable_box_vtype ()
55         {
56                 return ((TestStruct)(Box<TestStruct?> (new TestStruct (1)))).i;
57         }
58
59         public static int test_1_nullable_box_null_vtype ()
60         {
61                 return Box<TestStruct?> (null) == null ? 1 : 0;
62         }
63
64         public static int test_1_isinst_nullable_vtype ()
65         {
66                 object o = new TestStruct (1);
67                 return (o is TestStruct?) ? 1 : 0;
68         }
69
70         public static void stelem_any<T> (T[] arr, T elem) {
71                 arr [0] = elem;
72         }
73
74         public static T ldelem_any<T> (T[] arr) {
75                 return arr [0];
76         }
77
78         public static int test_1_ldelem_stelem_any_int () {
79                 int[] arr = new int [3];
80                 stelem_any (arr, 1);
81
82                 return ldelem_any (arr);
83         }
84
85         static object Box<T> (T t)
86         {
87                 return t;
88         }
89         
90         static T Unbox <T> (object o) {
91                 return (T) o;
92         }
93 }