Initial set of Ward sgen annotations (#5705)
[mono.git] / mono / tests / generic-method-patching.2.cs
1 using System;
2 using System.Collections.Generic;
3
4 public class MyDict<S,T> {
5     public void Add (S key, T value) {
6         S[] sa = new S[1];
7         T[] ta = new T[1];
8
9         sa[0] = key;
10         ta[0] = value;
11     }
12 }
13
14 public abstract class FastFunc<S,T> {
15     public abstract S Invoke (T bla);
16 }
17
18 public class StringFastFunc : FastFunc<string, int> {
19     public override string Invoke (int bla) {
20         return bla.ToString ();
21     }
22 }
23
24 public class ArrayFastFunc : FastFunc<byte [], int> {
25     public override byte [] Invoke (int bla) {
26         return new byte [bla];
27     }
28 }
29
30 public class IntCache<T> {
31     MyDict<int,T> cache;
32
33     public T Invoke (FastFunc<T,int> f, int bla) {
34         if (cache == null)
35             cache = new MyDict <int,T> ();
36
37         T value = f.Invoke (bla);
38
39         cache.Add (bla, value);
40
41         return value;
42     }
43 }
44
45 public class main {
46     public static int Main () {
47         StringFastFunc sff = new StringFastFunc ();
48         ArrayFastFunc aff = new ArrayFastFunc ();
49         IntCache<string> ics = new IntCache<string> ();
50         MyDict<string,string> dss = new MyDict<string,string> ();
51
52         dss.Add ("123", "456");
53
54         ics.Invoke (sff, 123);
55         ics.Invoke (sff, 456);
56
57         IntCache<byte []> ica = new IntCache<byte []> ();
58
59         ica.Invoke (aff, 1);
60         ica.Invoke (aff, 2);
61         ica.Invoke (aff, 3);
62
63         return 0;
64     }
65 }