具有自定义IEqualityComparer的Dictionary的XML序列化 [英] XML serialization of a Dictionary with a custom IEqualityComparer

查看:145
本文介绍了具有自定义IEqualityComparer的Dictionary的XML序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想序列化一个具有自定义IEqualityComparer的Dictionary。



我尝试使用DataContractSerializer,但是我无法使Comparer被序列化。 p>

我不能使用BinaryFormatter,因为这个



我总是可以这样做:

  var myDictionary = new MyDictionary(deserializedDictionary,myComparer); 

但这意味着我需要两倍的字典使用的内存。

解决方案

我只是读错误报告...


二进制


$ b $ p

如果您有图表,那么对象
图表的序列化失败,超过1320万美元
对象


大,你总是可能有一些问题。



你想尝试一个替代串行器吗? 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...

Binary serialization fails for object graphs with more than ~13.2 million objects.

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序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆