Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.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# NetDataContractSerializer序列化字典<>;。Comparer-DataContractSerializer没有?_C#_.net_Xml_Wcf_Serialization - Fatal编程技术网

C# NetDataContractSerializer序列化字典<>;。Comparer-DataContractSerializer没有?

C# NetDataContractSerializer序列化字典<>;。Comparer-DataContractSerializer没有?,c#,.net,xml,wcf,serialization,C#,.net,Xml,Wcf,Serialization,从.NET源代码中,我看到实现了以下方法:void GetObjectData(SerializationInfo,StreamingContext上下文) 查看GetObjectData()在我看来,比较器确实作为值添加到了SerializationInfo实例中,根据;存储序列化或反序列化对象所需的所有数据: 从DataContractSerializer输出XML: <ArrayOfKeyValueOfstringint xmlns="http://schemas.microsoft

从.NET源代码中,我看到实现了以下方法:
void GetObjectData(SerializationInfo,StreamingContext上下文)

查看
GetObjectData()
在我看来,
比较器
确实作为值添加到了
SerializationInfo
实例中,根据;存储序列化或反序列化对象所需的所有数据:

DataContractSerializer
输出XML:

<ArrayOfKeyValueOfstringint xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <KeyValueOfstringint>
        <Key>k</Key>
        <Value>123</Value>
    </KeyValueOfstringint>
</ArrayOfKeyValueOfstringint>
<ArrayOfKeyValueOfstringint z:Id="1" z:Type="System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" z:Assembly="0" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
    <Version z:Id="2" z:Type="System.Int32" z:Assembly="0" xmlns="">1</Version>
    <Comparer z:Id="3" z:Type="System.OrdinalComparer" z:Assembly="0" xmlns="">
        <_ignoreCase xmlns="http://schemas.datacontract.org/2004/07/System">true</_ignoreCase>
    </Comparer>
    <HashSize z:Id="4" z:Type="System.Int32" z:Assembly="0" xmlns="">3</HashSize>
    <KeyValuePairs z:Id="5" z:Type="System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][]" z:Assembly="0" z:Size="1" xmlns="">
        <KeyValuePairOfstringint xmlns="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
            <key z:Id="6">k</key>
            <value>123</value>
        </KeyValuePairOfstringint>
    </KeyValuePairs>
</ArrayOfKeyValueOfstringint>
从XML中可以明显看出,当使用
DataContractSerializer
进行序列化/反序列化时,
比较器
为什么会消失-它根本不在XML中

将类型添加到
DataContractSerializer
的已知类型中没有任何区别

我见过类似的问题(,),但据我所知,没有人真正解决这种行为背后的原因,我想了解为什么
DataContractSerializer
跳过
GetObjectData()
,从而跳过
比较器的序列化

<ArrayOfKeyValueOfstringint xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <KeyValueOfstringint>
        <Key>k</Key>
        <Value>123</Value>
    </KeyValueOfstringint>
</ArrayOfKeyValueOfstringint>
<ArrayOfKeyValueOfstringint z:Id="1" z:Type="System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" z:Assembly="0" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
    <Version z:Id="2" z:Type="System.Int32" z:Assembly="0" xmlns="">1</Version>
    <Comparer z:Id="3" z:Type="System.OrdinalComparer" z:Assembly="0" xmlns="">
        <_ignoreCase xmlns="http://schemas.datacontract.org/2004/07/System">true</_ignoreCase>
    </Comparer>
    <HashSize z:Id="4" z:Type="System.Int32" z:Assembly="0" xmlns="">3</HashSize>
    <KeyValuePairs z:Id="5" z:Type="System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][]" z:Assembly="0" z:Size="1" xmlns="">
        <KeyValuePairOfstringint xmlns="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
            <key z:Id="6">k</key>
            <value>123</value>
        </KeyValuePairOfstringint>
    </KeyValuePairs>
</ArrayOfKeyValueOfstringint>