2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / tests / generic-method-patching.2.cs
blob67d8650464720537dc71e0d81e5bc366615e483a
1 using System;
2 using System.Collections.Generic;
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];
9 sa[0] = key;
10 ta[0] = value;
14 public abstract class FastFunc<S,T> {
15 public abstract S Invoke (T bla);
18 public class StringFastFunc : FastFunc<string, int> {
19 public override string Invoke (int bla) {
20 return bla.ToString ();
24 public class ArrayFastFunc : FastFunc<byte [], int> {
25 public override byte [] Invoke (int bla) {
26 return new byte [bla];
30 public class IntCache<T> {
31 MyDict<int,T> cache;
33 public T Invoke (FastFunc<T,int> f, int bla) {
34 if (cache == null)
35 cache = new MyDict <int,T> ();
37 T value = f.Invoke (bla);
39 cache.Add (bla, value);
41 return value;
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> ();
52 dss.Add ("123", "456");
54 ics.Invoke (sff, 123);
55 ics.Invoke (sff, 456);
57 IntCache<byte []> ica = new IntCache<byte []> ();
59 ica.Invoke (aff, 1);
60 ica.Invoke (aff, 2);
61 ica.Invoke (aff, 3);
63 return 0;