版本序列化文件 [英] versioning serialized files

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

问题描述

我有一个序列化的文件(类型的IDocument的)到磁盘的工作程序。从那里有,我已经做了另一个应用程序,可以打开该文档(的IDocument实现IPrintDocument)进行查看。

I've got a working app that serializes a document (of type IDocument) to disk. From there there's another app that I've made that can open that document (IDocument implements IPrintDocument) for viewing.

让我们假设我写了一个IDocument还到磁盘,然后一个星期后场被添加到的IDocument对象。这两种写入文件,并打开他们的一个节目用的IDocument的新版本更新。然后,它会打破(我假设 - 还没有机会来检查,我放眼望去这里)试图打开以前的IDocument版本时。 ?是否有缓解这种问题已知模式

Let's assume that I've written an IDocument to disk, and then a week later a field gets added to the IDocument object. Both the program that writes the files and the one that opens them are updated with this new 'version' of IDocument. It will then break (I assume - haven't had a chance to check, I'm looking ahead here) when trying to open the previous IDocument version. Is there a known pattern that alleviates this kind of problem?

推荐答案

是 - 使用序列化机制是的耐版本

Yes - use a serialization mechanism which is tolerant to versioning.

可以预见的是,我会使用谷歌的协议缓冲器建议,对其中有在至少 2 可行 .NET实现。只要你细心,Protocol Buffers的都是向前和向后兼容 - 你可以阅读使用旧的代码,反之亦然,而旧的代码仍然能够保持它并不了解信息的新消息

Predictably enough, I'm going to suggest using Google's Protocol Buffers, for which there are at least two viable .NET implementations. So long as you're careful, Protocol Buffers are both backward and forward compatible - you can read a new message with old code and vice versa, and the old code will still be able to preserve the information it doesn't understand.

另一种方法是XML,无论是使用.NET的内置XML序列化与否。内置的序列化不就我所知版本方面特别灵活。

Another alternative is XML, whether using .NET's built-in XML serialization or not. The built-in serialization isn't particularly flexible in terms of versioning as far as I'm aware.

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

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