哪个更好地处理版本控制?XmlSerializer 与 DataContractSerializer? [英] Which One Better Handles Versioning? XmlSerializer vs. DataContractSerializer?

查看:24
本文介绍了哪个更好地处理版本控制?XmlSerializer 与 DataContractSerializer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要序列化一个对象,反序列化时程序集版本可能发生了变化.此外,对象可能会发生一些变化.

In need to serialize an object and it's possible that the assembly version changed while deserialization. Additionally it can happen, that the object changes a bit.

XmlSerializer 不存储类型信息,如果对象稍微改变,它不会失败,但 XmlSerializer 无法序列化来自我无法用属性标记的超类的私有或内部属性.所以我查看了 DataContractSerializer.到目前为止看起来不错,超类的私有/内部属性的问题将得到解决,所有属性都必须标记,我不需要它们,但是类型信息呢?如果删除、重命名或添加某些属性,DataContractSerializer 的行为如何?

The XmlSerializer does not store type information and if the object changes a bit, it just does not fail, but the XmlSerializer can not serialize private or internal properties from a super class I can not mark with attributes. So I had a look at the DataContractSerializer. It looks fine so fare, the problem with the private / internal properties of the super class would be solved, all properties have to be marked and I don't need them, but what about the type information? And how does the DataContractSerializer behave, if some properties are removed, renamed or added?

推荐答案

我使用 DataContractSerializer 进行了测试,似乎 DataContractSerializer 对对象更改非常宽容,因此我将使用该方法.

I made a test with the DataContractSerializer and it seems as the DataContractSerializer is very tolerant against object changes, so I'll use the approach.

这篇关于哪个更好地处理版本控制?XmlSerializer 与 DataContractSerializer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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