Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用反射将非泛型字典转换为泛型字典,而不使用泛型参数_C#_Xml_Dictionary_Generics_Reflection - Fatal编程技术网

C# 使用反射将非泛型字典转换为泛型字典,而不使用泛型参数

C# 使用反射将非泛型字典转换为泛型字典,而不使用泛型参数,c#,xml,dictionary,generics,reflection,C#,Xml,Dictionary,Generics,Reflection,我正在为进行自定义XML序列化,到目前为止,我已经完全涵盖了除“dict”之外的所有类型。一些dict本质上是这样的对象: 1 轨道ID1 名婴儿 艺术家贾斯汀·比伯 [...] 我已经处理过了 property.SetValue(obj,xmlReader.ReadElementContentAs(propertyType,null)) 对于数组,我能够使用非类型化的Array类(使用ArrayList类来构建它),它允许使用类型变量而不是泛型,然后可以方便地直接进入SetValue方法并自

我正在为进行自定义XML序列化,到目前为止,我已经完全涵盖了除“dict”之外的所有类型。一些dict本质上是这样的对象:

1
轨道ID1
名婴儿
艺术家贾斯汀·比伯
[...]
我已经处理过了

property.SetValue(obj,xmlReader.ReadElementContentAs(propertyType,null))

对于数组,我能够使用非类型化的
Array
类(使用
ArrayList
类来构建它),它允许使用类型变量而不是泛型,然后可以方便地直接进入
SetValue
方法并自动转换为
int[]
或对象中的任何其他泛型

ArrayList array = new ArrayList();
do
{
    array.Add(GetDictValue(arrayReader, elementType));
}
while (arrayReader.ReadToFollowing(elementTypeName));
property.SetValue(obj, array.ToArray(elementType));

但我找不到任何这样的方法来为字典做这件事<没有通用参数,代码>哈希表
无法转换为通用
字典。

我将创建第二个xmlreader来读取子项:

            XmlReader reader = XmlReader.Create(@"c:\temp\test.xml");
            reader.ReadToFollowing("ENVELOPE");
            StringReader sReader = new StringReader(reader.ReadInnerXml());
            XmlReader childReader = XmlReader.Create(sReader);
            childReader.MoveToContent();
            reader.MoveToContent();

如果以
IDictionary
开头,此“问题”是否仍然存在?所有键看起来都是字符串,值可以混合。。