Merge pull request #5382 from kumpera/pedump_fix
[mono.git] / mono / tests / generic-delegate.2.cs
1 using System;
2
3 public class ClassA {}
4
5 public delegate int IntDelegate (int x);
6 public delegate T[] TDelegate<T> ();
7
8 public class Gen<T> {
9         public int intFunction (int x) {
10                 return x + 1;
11         }
12
13         public IntDelegate getIntDelegate () {
14                 return intFunction;
15         }
16
17         public virtual int virtIntFunction (int x) {
18                 return x + 2;
19         }
20
21         public IntDelegate getVirtIntDelegate () {
22                 return virtIntFunction;
23         }
24
25         public T[] tFunction () {
26                 return new T[3];
27         }
28
29         public TDelegate<T> getTDelegate () {
30                 return tFunction;
31         }
32
33         public static T[] staticTFunction () {
34                 return new T[3];
35         }
36
37         public TDelegate<T> getStaticTDelegate () {
38                 return staticTFunction;
39         }
40 }
41
42 public class main {
43         public static int Main () {
44                 Gen<ClassA> ga = new Gen<ClassA> ();
45                 IntDelegate id = ga.getIntDelegate ();
46                 TDelegate<ClassA> tda = ga.getTDelegate ();
47                 IntDelegate vid = ga.getVirtIntDelegate ();
48                 TDelegate<ClassA> stda = ga.getStaticTDelegate ();
49
50                 if (id (123) != 124)
51                         return 1;
52                 if (tda ().GetType () != typeof (ClassA[]))
53                         return 1;
54                 if (vid (123) != 125)
55                         return 1;
56                 if (stda ().GetType () != typeof (ClassA[]))
57                         return 1;
58
59                 tda = (TDelegate<ClassA>)Delegate.CreateDelegate (typeof (TDelegate<ClassA>),
60                                 typeof (Gen<ClassA>).GetMethod ("staticTFunction"));
61
62                 if (tda ().GetType () != typeof (ClassA[]))
63                         return 1;
64
65                 return 0;
66         }
67 }