问题描述
我想序列化一个具有自定义IEqualityComparer的Dictionary。我尝试使用DataContractSerializer,但是我无法使Comparer被序列化。 p>
我不能使用BinaryFormatter,因为。
我总是可以这样做:
var myDictionary = new MyDictionary(deserializedDictionary,myComparer);
但这意味着我需要两倍的字典使用的内存。
我只是读错误报告...
大,你总是可能有一些问题。
你想尝试一个替代串行器吗? protobuf-net是按照Google协议缓冲区格式定制的二进制序列化程序,可能适用于较大的集合,特别是组模式。
I want to serialize a Dictionary that has a custom IEqualityComparer.
I've tried using DataContractSerializer but I can't get the Comparer to be serialized.
I can't use BinaryFormatter because of this.
I can always do something like:
var myDictionary = new MyDictionary(deserializedDictionary, myComparer);
But that means I'd need twice the memory the dictionary uses.
I just read the error report...
if you have a graph that big, you always may have some problems.
Would you like to try an alternative serializer? "protobuf-net" is a bespoke binary serializer following Google's protocol buffers format, and may work for larger sets, especially in "group" mode.
这篇关于具有自定义IEqualityComparer的Dictionary的XML序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!