Merge pull request #4935 from lambdageek/dev-handles-may
[mono.git] / mcs / tests / test-394.cs
1 // Compiler options: -langversion:default
2 //
3 // Test for contravariance support in delegates
4 //
5
6 using System;
7
8  public class A {
9          protected string name;
10          
11          public A (string name)
12          {
13                  this.name = "A::" + name;
14          }
15
16          public A ()
17          {
18          }
19
20          public string Name {
21                  get {
22                          return name;
23                  }
24          }
25  }
26
27  public class B : A {
28          public B (string name)
29          {
30                  this.name = "B::" + name;
31          }
32
33          public B ()
34          {
35          }
36  }
37
38  public class C : B {
39          string value;
40
41          public C (string name, string value)
42          {
43                  this.name = "C::" + name;
44                  this.value = value;
45          }
46
47          public string Value {
48                  get {
49                          return value;
50                  }
51          }
52  }
53
54  public class Tester {
55
56          delegate string MethodHandler (C c);
57
58          static string MethodSampleA (A value)
59          {
60                  return value.Name;
61          }
62
63          static string MethodSampleB (B value)
64          {
65                  return value.Name;
66          }
67
68          static string MethodSampleC (C value)
69          {
70                  return value.Name + " " + value.Value;
71          }
72
73          public static void Main ()
74          {
75                  MethodHandler da = MethodSampleA;
76                  MethodHandler db = MethodSampleB;
77                  MethodHandler dc = MethodSampleC;
78
79                  C a = new C ("Hello", "hello");
80                  C b = new C ("World", "world");
81                  C c = new C ("!", "!!!");
82
83                  Console.WriteLine (da (a));
84                  Console.WriteLine (db (b));
85                  Console.WriteLine (dc (c));
86          }
87         
88  }
89