最佳实践序列化和反序列化不同版本的.NET对象 [英] Best practice to serialize and deserialize .net objects across versions

查看:208
本文介绍了最佳实践序列化和反序列化不同版本的.NET对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对象是序列化到使用.NET XML序列化的数据库。该对象可以随时间而改变,因此,存在于数据库中,在同一时间的多个版本。

Objects are serialized to a database using the .NET XML serializer. The object can change over time, and therefore multiple versions exist in the database at one time.

有关来构建你的code,这样你仍然可以反序列化该对象到最新版本的最佳方法的任何建议。 (接口/地图/手动序列化等)

Any suggestions for the best way to construct your code, so that you can still deserialize this object into the latest version. (interfaces / maps / manual serialization etc.)

推荐答案

这一切都取决于你的应用程序。它是一个分布式丰富的应用程序,其中旧的应用程序可以从一个中央数据库或其他来源遇到新的数据对象? (就像旧版本的Office应用程序需要有处理新的文档格式的一些方法。)

This all depends on your application. Is it a distributed rich application where old applications may encounter new data objects from a central database or other source? (Much like older versions of office applications need to have some ways of dealing with newer document formats.)

如果是这样,自定义序列化和反序列化与明确的架构版本编号的,我会说。我把每个元素和属性上明确的元数据,说明读者是否必须了解的元素/属性(如果不是默认值)。当然,这会占用相当多的空间,并增加code复杂......

If so, custom serialization and deserialization with explicit schema version numbering, I'd say. I'd put explicit metadata on each element and attribute, stating whether a reader must understand the element/attribute (and default values if not). This can of course consume quite a lot of space and increase code complexity...

但答案实际上取决于你为什么序列化到数据库。你不是有兴趣使用该数据库中的关系capabiities?否则,O / R映射解决方案可能会感兴趣。

But the answer really depends on why you are serializing to a database. You're not interested in using the database for its relational capabiities? Otherwise, an O/R mapping solution might be of interest.

这篇关于最佳实践序列化和反序列化不同版本的.NET对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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