Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / gtest-054.cs
1 //
2 // Conversions involving type parameters (26.7.4).
3 // This is a compilation-only test since some of the explict
4 // conversions would trigger an InvalidCastException.
5 //
6
7 using System;
8
9 interface Foo
10 {
11         void Hello ();
12 }
13
14 class A
15 { }
16
17 class B : A, Foo
18 {
19         public void Hello ()
20         { }
21
22         public static implicit operator C (B b)
23         {
24                 return new C ();
25         }
26 }
27
28 class C
29 {
30         public static explicit operator B (C c)
31         {
32                 return new B ();
33         }
34 }
35
36 class Test
37 {
38         static void Simple<T> (T t)
39         {
40                 object o = t;
41                 t = (T) o;
42                 Foo foo = (Foo) t;
43                 t = (T) foo;
44         }
45
46         static void Interface<T> (T t)
47                 where T : Foo
48         {
49                 Foo foo = t;
50         }
51
52         static void Class<T> (T t)
53                 where T : B
54         {
55                 B b = t;
56                 A a = t;
57                 Foo foo = t;
58                 t = (T) b;
59                 t = (T) a;
60                 t = (T) foo;
61                 C c = t;
62                 t = (T) c;
63         }
64
65         static void Array<T> (T[] t)
66         {
67                 object o = t;
68                 Array a = t;
69                 t = (T []) o;
70                 t = (T []) a;
71         }
72
73         public static void Main ()
74         { }
75 }