【发布时间】:2013-12-18 10:38:18
【问题描述】:
问题:我有一些像这样的可序列化类:
public abstract class Person {}
public class Student : Person {}
public class Teacher : Person {}
[Serializable()]
[XmlIncludeAttribute(typeof(Student))]
[XmlIncludeAttribute(typeof(Teacher))]
public class Room
{
[XmlElementAttribute(??)]
public Person[] persons;
}
假设我有一个像这样的对象:
Room r = new Room();
r.persons= new Person[]{new Student(), new Teacher()};
我的结果:当我序列化它时,它会是这样的:
<Room>
<Person />
<Person />
</Room>
我需要什么:我需要的是这个,但我不知道
<Room>
<Student/>
<Teacher/>
</Room>
有什么帮助吗?
【问题讨论】:
标签: c# xml serialization xml-serialization abstract-class