瀏覽代碼

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

Thomas Nind 4 年之前
父節點
當前提交
7e99d44b52
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      UICatalog/Scenarios/AllViewsTester.cs

+ 14 - 0
UICatalog/Scenarios/AllViewsTester.cs

@@ -344,6 +344,20 @@ namespace UICatalog {
 
 		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
 			var view = (View)Activator.CreateInstance (type);