Browse Source

Fixed CreateClass to create a generic MyClass<object> when MyClass<T> is passed (#1153)

Thomas Nind 4 years ago
parent
commit
7e99d44b52
1 changed files with 14 additions and 0 deletions
  1. 14 0
      UICatalog/Scenarios/AllViewsTester.cs

+ 14 - 0
UICatalog/Scenarios/AllViewsTester.cs

@@ -344,6 +344,20 @@ namespace UICatalog {
 
 
 		View CreateClass (Type type)
 		View CreateClass (Type type)
 		{
 		{
+			// If we are to create a generic Type
+			if (type.IsGenericType) {
+
+				// For each of the <T> arguments
+				List<Type> typeArguments = new List<Type> ();
+
+				// use <object>
+				foreach (var arg in type.GetGenericArguments ()) {
+					typeArguments.Add (typeof (object));
+				}
+
+				// And change what type we are instantiating from MyClass<T> to MyClass<object>
+				type = type.MakeGenericType (typeArguments.ToArray ());
+			}
 			// Instantiate view
 			// Instantiate view
 			var view = (View)Activator.CreateInstance (type);
 			var view = (View)Activator.CreateInstance (type);