[runtime] Synthesize IList and IReadOnlyList for the element type of enum errays...
[mono.git] / mono / tests / generic-valuetype-interface.2.cs
1 using System;
2 using System.Collections.Generic;
3
4 public struct GenStruct<T> {
5     public int inc (int i) {
6         return i + 1;
7     }
8
9     public T[] newArr () {
10         return new T [3];
11     }
12 }
13
14 public class Bla {
15     public bool work (IList<string> l) {
16         foreach (string s in l) {
17             if (s.Length != 1)
18                 return false;
19         }
20         return true;
21     }
22 }
23
24 public interface GenInterface<T> {
25     T[] newArr ();
26 }
27
28 public struct GenIntStruct<T> : GenInterface<T> {
29     public T[] newArr () {
30         return new T [3];
31     }
32 }
33
34 public interface GenFactory<T> {
35     GenInterface<T> makeInterface ();
36 }
37
38 public class Gen<T> : GenFactory<T> {
39     public GenInterface<T> makeInterface () {
40         return new GenIntStruct<T> ();
41     }
42 }
43
44 public class NonGen : GenFactory<string> {
45     public GenInterface<string> makeInterface () {
46         return new GenIntStruct<string> ();
47     }
48 }
49
50 public class main {
51     public static bool testInterface (GenFactory<string> gf) {
52         GenInterface<string> gi = gf.makeInterface ();
53         if (gi.newArr ().GetType () != typeof (string []))
54             return false;
55         return true;
56     }
57
58     public static int Main () {
59         GenStruct<object> gso = new GenStruct<object> ();
60         GenStruct<string> gss = new GenStruct<string> ();
61
62         if (gso.inc (1) != 2)
63             return 1;
64         if (gss.inc (2) != 3)
65             return 1;
66
67         if (gso.newArr ().GetType () != typeof (object []))
68             return 1;
69         if (gss.newArr ().GetType () != typeof (string []))
70             return 1;
71
72         Gen<string> g = new Gen<string> ();
73         testInterface (g);
74
75         NonGen ng = new NonGen ();
76         testInterface (ng);
77
78         Bla bla = new Bla ();
79         string [] arr = { "a", "b", "c" };
80
81         if (!bla.work (arr))
82             return 1;
83
84         return 0;
85     }
86 }