我通过反射来实例化单维Int32
阵列的List<T>
。当我实例使用列表:无法投射列表<int[*]>到列表<int[]>用反射实例化
Type typeInt = typeof(System.Int32);
Type typeIntArray = typeInt.MakeArrayType(1);
Type typeListGeneric = typeof(System.Collections.Generic.List<>);
Type typeList = typeListGeneric.MakeGenericType(new Type[] { typeIntArray, });
object instance = typeList.GetConstructor(Type.EmptyTypes).Invoke(null);
我看到名单就这一奇怪的现象:
如果我通过反思与它接口,它似乎正常行为,但是,如果我尝试它转换为它的实际类型:
List<int[]> list = (List<int[]>)instance;
我得到这个异常:
无法将类型为'System.Collections.Generic.List`1 [System.Int32 [*]]'的对象转换为键入'System.Collections.Generic.List`1 [System.Int32 []]'。
任何想法可能导致这种情况或如何解决它?我正在使用.net 4.0上的visual studio 2010 express。
我很好奇为什么它会在查看当地人时导致奇怪的列表行为,但现在这个问题已经解决了。谢谢。 – Einherjar