C# NetDataContractSerializer序列化字典<>;。Comparer-DataContractSerializer没有?
从.NET源代码中,我看到实现了以下方法: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
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>