2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / tests / generic-delegate.2.cs
blob4123893f0d080e6773b063ff19cd2be317b849c5
1 using System;
3 public class ClassA {}
5 public delegate int IntDelegate (int x);
6 public delegate T[] TDelegate<T> ();
8 public class Gen<T> {
9 public int intFunction (int x) {
10 return x + 1;
13 public IntDelegate getIntDelegate () {
14 return intFunction;
17 public virtual int virtIntFunction (int x) {
18 return x + 2;
21 public IntDelegate getVirtIntDelegate () {
22 return virtIntFunction;
25 public T[] tFunction () {
26 return new T[3];
29 public TDelegate<T> getTDelegate () {
30 return tFunction;
33 public static T[] staticTFunction () {
34 return new T[3];
37 public TDelegate<T> getStaticTDelegate () {
38 return staticTFunction;
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 ();
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;
59 tda = (TDelegate<ClassA>)Delegate.CreateDelegate (typeof (TDelegate<ClassA>),
60 typeof (Gen<ClassA>).GetMethod ("staticTFunction"));
62 if (tda ().GetType () != typeof (ClassA[]))
63 return 1;
65 return 0;