DataContractSerializer的VS XmlSerializer的:优点和每一个串行的缺点 [英] DataContractSerializer vs XmlSerializer: Pros and Cons of each serializer

查看:94
本文介绍了DataContractSerializer的VS XmlSerializer的:优点和每一个串行的缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌面应用程序中使用的XmlSerializer 序列化对象。我建议利用的DataContractSerializer 代替。
在这情况下,我应该使用的DataContractSerializer

My desktop application serializes objects using XmlSerializer. I was suggested to leverage DataContractSerializer instead.
Under which scenarios should I use DataContractSerializer?

感谢

评论。
1.输出XML文件存储在本地。没有任何其他应用程序序列化从该XML文件中的对象。
2.我的应用程序的.NET Framework 3.5 SP1运行。

Comments.
1. The output XML file is stored locally. No other applications deserialize objects from that XML file.
2. My application runs with .NET Framework 3.5 SP1.

推荐答案

丹Rigsby对此有最终的帖子 - !去阅读

Dan Rigsby has the ultimate post on this - go read it!

<一个href="http://web.archive.org/web/20130430190551/http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/">XmlSerializer主场迎战的DataContractSerializer(Web归档)

他说,所有的有说了,这是一个很令人信服的方式。

He says all there is to say, and it a very convincing way.

在短期:

XmlSerializer的:

XmlSerializer:

  • 在已经存在了很长一段时间
  • 是退出;一切公众被序列化,除非你告诉它不要([XmlIgnore])

DataContractSerializer的是:

DataContractSerializer is:

  • 在镇上新来的小子
  • 优化速度(快10%,比XmlSerializer的,通常情况下)
  • 在选择加入 - 只有东西,你专门标记为 [数据成员] 将被序列化
  • 但任何标记 [数据成员] 将被序列化 - 无论是公开私人
  • 在不支持XML属性(速度的原因)
  • the new kid in town
  • optimized for speed (about 10% faster than XmlSerializer, typically)
  • "opt-in" - only stuff you specifically mark as [DataMember] will be serialized
  • but anything marked with [DataMember] will be serialized - whether it's public or private
  • doesn't support XML attributes (for speed reasons)

这篇关于DataContractSerializer的VS XmlSerializer的:优点和每一个串行的缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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