Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2014-01-06 14:07:35 +0400
committerMarek Safar <marek.safar@gmail.com>2014-01-06 14:10:09 +0400
commit2ce91c24814b1d5281ec70a6e0a9d580961cd291 (patch)
tree133c89f96d0c15330c1d6e37ee4c6e9f7f242818 /mcs/tests/gtest-602.cs
parent605b9491419b4965817c94056c168e2ec61a08ae (diff)
[mcs] Method group caching needs to consider type arguments as well. Fixes #17059
Diffstat (limited to 'mcs/tests/gtest-602.cs')
-rw-r--r--mcs/tests/gtest-602.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/mcs/tests/gtest-602.cs b/mcs/tests/gtest-602.cs
new file mode 100644
index 00000000000..87ae36011e6
--- /dev/null
+++ b/mcs/tests/gtest-602.cs
@@ -0,0 +1,54 @@
+using System.Collections.Generic;
+using System;
+
+public class Factory<TKey, TBase>
+{
+ delegate T InstantiateMethod<T> ();
+
+ Dictionary<TKey, InstantiateMethod<TBase>> _Products = new Dictionary<TKey, InstantiateMethod<TBase>> ();
+
+ public void Register<T> (TKey key) where T : TBase, new()
+ {
+ _Products.Add (key, Constructor<T>);
+ }
+
+ public TBase Produce (TKey key)
+ {
+ return _Products [key] ();
+ }
+
+ static TBase Constructor<T> () where T : TBase, new()
+ {
+ return new T ();
+ }
+}
+
+class BaseClass
+{
+}
+
+class ChildClass1 : BaseClass
+{
+}
+
+class ChildClass2 : BaseClass
+{
+}
+
+class TestClass
+{
+ public static int Main ()
+ {
+ var factory = new Factory<byte, BaseClass> ();
+ factory.Register<ChildClass1> (1);
+ factory.Register<ChildClass2> (2);
+
+ if (factory.Produce (1).GetType () != typeof (ChildClass1))
+ return 1;
+
+ if (factory.Produce (2).GetType () != typeof (ChildClass2))
+ return 2;
+
+ return 0;
+ }
+} \ No newline at end of file