代码如下,问题就出在红字部分:
Code 1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Reflection; 5 6namespace Test 7{ 8 class CT { } 9 class CT1:CT { }10 class CT2 : CT { }11 class CT3 : CT { }12 class CT4 : CT { }13 class CT5 : CT { }14 class CT6 : CT { }15 class Base<T> : List<T> where T : CT { }16 class class1: Base<CT1> { }17 class class2: Base<CT2> { }18 class class3: Base<CT3> { }19 class class4: Base<CT4> { }20 class class5: Base<CT5> { }21 class class6: Base<CT6> { }2223 class test<T> where T : CT24 {25 private static Dictionary<string, Base<T>> d;26 private static object obj = new object();27 public static Dictionary<string, Base<T>> Caches28 {29 get30 {31 if (d == null)32 {33 lock (obj)34 {35 if (d == null)36 Load();37 }38 }39 return d;40 }41 }424344 private static void Load()45 {4647 Type[] tys = Assembly.GetExecutingAssembly().GetTypes();48 foreach (Type t in tys)49 if (t.BaseType.Name == "Base`1")50 {51 XX x = (XX)Assembly.GetExecutingAssembly().CreateInstance("Test." + t.Name);52 d.Add(t.Name, x);53 }54 }55 }56}
两个 XX 应该是什么,怎么写?我头疼了半天,试了好几种方法,还是没搞定,请教各位,致谢先~
1 回答
- 1 回答
- 0 关注
- 580 浏览
添加回答
举报
0/150
提交
取消