对象图形序列化的.NET和code版本升级 [英] Object graph serialization in .NET and code version upgrades

查看:111
本文介绍了对象图形序列化的.NET和code版本升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些对象图序列化到光盘

I need to serialize some object graphs to disc

什么困难,我可能会遇到,如果我改动了一个类,然后尝试反序列化的旧版本?

What difficulties am I likely to encounter if I make changes to a class, then try to deserialize an old version?

做一些串行处理比别人这更好的?

Do some serializers handle this better than others?

什么是处理这种情况的标准方法是什么?

What is the standard way of handling such a scenario?

例如,在的code一个新版本,我需要保留所有的老班让反序列化的旧文件时,我可以做这样的老班,然后将数据迁移到新类?是否会改变类的名字/空间突破反序列化?

For example, in a new version of the code, do I need to retain all the old classes so that when deserializing an old file i can do so to the old class, then migrate the data to the new class? Will changing the class' name/namespace break deserialization?

感谢您的任何意见

推荐答案

嗯,我记得,存在的问题启动后:

Well, as I remember, the problems starts after:

  • 添加一个新的字段/属性的一类;
  • 更改现有字段/属性的类型。

您可以自定义序列来处理你自己的版本问题

You can have custom serialization to handle versioning problems on you own.

不过,我会建议使用<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"相对=nofollow> 的DataContractSerializer 一起的最佳做法:数据协定版本为最常见的情况。

But I would recommend to use DataContractSerializer along with Best Practices: Data Contract Versioning for the most common cases.

这篇关于对象图形序列化的.NET和code版本升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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