XML序列化,继承和抽象类。 [英] XML serialization, inheri and abstract classes.
问题描述
____所有,希望这是发布此内容的正确论坛(我在这里有点新鲜)。
____ all, hope this is the right forum to post this in (I'm kinda new here).
无论如何,我刚开始用c#学习XML和.net我遇到了一些我无法回答的问题。
Anyway I just started to learn XML with c# and .net and I have some problems that I can't find answer on.
我有一个列表我想用XML序列化它包含不同种类的动物。链看起来像这样
I'm having a list I want to serialize with XML and it contains different kinds of animals. The chain is looking kinda like this
动物(摘要) - > Bird(摘要,继承自Animal) - > Dove(继承自Bird)。
Animal(abstract) -> Bird(Abstract, inherit from Animal) - > Dove(Inherit from Bird).
我遇到的第一个问题是他抱怨不知道Dove(因为这个名单实际上保留了动物)。那么
The first problem I came up to was that he complained about not knowing about Dove (well because the list actully kept Animals). So then
我读到我可以在Animal类中放置一个XMLInclude,所以我做了并且它有效(woho)。我现在可以创建XML文件,但这是一个问题。
I read that I could put a XMLInclude in the Animal class and so I did and it worked (woho). I could now create the XML file but it is one problem.
Bird类具有属性,即使列表中有Doves,XML文档似乎也不包含它们。有什么方法可以解决这个问题,所以当我序列化一个列表时,我得到Bird的所有属性< Animal>?
The Bird class have attributes and the XML document don't seems to include them even if the list have a Doves. Is there some way I can get around that so I get all the attributes from Bird when I serialize a list<Animal>?
推荐答案
您好,
您能否发布您的问题的工作重复?您的描述过于笼统,我们无法确定问题究竟是什么。
Could you please post a working repro of your problem? Your description is too general for us to be able to tell what the problem really is.
谢谢,
这篇关于XML序列化,继承和抽象类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!