从乘法类和继承的类保存/加载类数据. [英] Save/Load Class data from multiply classes and inherited classes.

查看:82
本文介绍了从乘法类和继承的类保存/加载类数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,所以我最近阅读了有关XML和如何从类中保存数据并将其重新加载的信息,但是我看到的所有示例仅集中于没有接口或继承类的单个类,因此我有点困惑关于如何以一种简单的方式做到这一点.

我的程序有1个抽象父类,其中有多个子类和子子类,我将尝试在下面创建类图:

超类-> FirstChild-> SecondChild
超类-> ThirdChild
SomeRandomConstantClass(用于容纳FirstChild所需的某些项)

他们每个人都放在一个超级类列表中(以便将所有内容放在一个地方),但是我现在想知道ii可以简单地将每个数据保存到单个XML中,然后在单击时将其重新加载到列表/类中加载按钮?

正如我说过的那样,我已经在一个类上看到了如何对单个项目执行操作,但对多个项目和继承却不执行操作,因此,如果有人可以提供一些有用的示例代码或有关如何执行操作的文章,那将是非常棒的. />
谢谢-Jackie

Hi everyone, so i recently read about XML and saving data from classes and load it back in, but all examples I''ve seen only focus on single classes with no interfaces or inherited classes, so I''m alittle confused about how i can do this en a easy way.

My program have 1 abstract super class that have multiple child classes and child-child classes, I''ll try to make a class diagram here below:

Superclass --> FirstChild --> SecondChild
Superclass --> ThirdChild
SomeRandomConstantClass (to hold some Items needed by FirstChild)

Everyone of them is putted in a list of super classes (to be able to have everything in one place) but i now wanna know how i i simply can save every data to a single XML and then load it back into the list/classes when clicking a load button?

As I said I''ve seen it on a single class how to do it with single items, but not with multiple items and inheritance so it would be awesome if some people could provide some useful sample code or articles on how to.

Thanks - Jackie

推荐答案

确实存在支持任何对象图(不仅是树)而且与数据无关的方法.这是数据合同:
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

另请参阅我过去的答案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [
The approach supporting absolutely any object graph (not only tree) and agnostic of the data does exist. This is Data Contract:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please also see my past answers:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].

Internally, it is based on System.Reflection.Emit. If you need some explanation of how it works, I can explain.

—SA


这篇关于从乘法类和继承的类保存/加载类数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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