XML序列化重载 [英] XML Serialization Overload

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

问题描述



我大约有50个类(C#2010),所以将定期更新类结构本身的新内容.

无论是要添加,删除还是重命名的某个字段.
最终,我需要分配一个类的从1到几千个实例的任何东西,这些实例与字典结合在一起.
然后在3d图形设备上输出.

我正在查看在类和本地数据库之间的类内容的保存/加载.这些类也包含受保护的字段和成员.

我已经对2种不同的序列化选项进行了一些研究.

我试图找到一种方法来适应二进制序列化,也许可以与保留原始类状态的数据加载结合起来.,
当从先前的xml保存更改了类的结构时.

任何建议,将不胜感激.

问候,
X

Hi There,

i have about 50 classes (C# 2010) or so that will get updated periodically with new content on the class structure itself.

Whether it''s some field that would be added, removed or renamed.
At the end of the day i need to allocate anything from 1 to a few thousand instances of a class, which gets hold together with dictionaries.
Then output on a 3d graphics device.

I''m looking at saving / loading between the classes and local database for the class content. The classes contains protected fields and members as well.

I''ve done some research on the 2 different serialization options.

I''m trying to find a way how to accomodate binary serialization perhaps in conjunction of preserving the loading of the data from the original class state.,
when the structure of the class has been changed from the previous xml save.

Any advise would be appreciated.

Regards,
X

推荐答案

我大约有50个类(C#2010),因此将定期使用类结构本身的新内容进行更新." =听起来经常重写应用程序不是吗?还是要说类的实例?

我正在寻找有关类内容的类和本地数据库之间的保存/加载",再次弄清楚类或实例吗?如果是班级的话,那给我一个导演电影《变形金刚50》的想法,以及家属如何适应他们.

但是,对于xml序列化,您可以mark a field optional 当类结构更改时,可以使新字段为可选.这样您仍然可以反序列化对象的旧版本,并在deserialization events处具有一些业务逻辑来填充那些未初始化的字段.希望有帮助.

一些老派学生说:班级应关闭以进行修改,并开放以进行扩展".现在是时候重新考虑您是否对此有重要要求.
"i have about 50 classes (C# 2010) or so that will get updated periodically with new content on the class structure itself." = Isn''t it sounds rewriting the application often? or you meant to say instance of the classes?

"I''m looking at saving / loading between the classes and local database for the class content" Again make it clear the classes or instances?. If it is classes then it gives me an idea of directing a movie "Transformers 50" and how the dependents adapted to them.

However for xml serialization you can mark a field optional When your class structure changes you can make the new fields optional. So that still you can deserialize the old version of the object and have some business logic at the deserialization events to populate those uninitialized fields. Hope that helps.

Some old school people said "Classes should be closed for modification and open for extension". Now it is time to rethink if you have a vital requirement for this.


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

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