我有: public class B { public string Some { get; set; }}public class D : B{ public string More { get; set; }}[KnownType(typeof(D))]public class X{ public B[] Col { get; set; }} 我想自动读/写XML,如下所示: X Col B Some="val1"
public class B { public string Some { get; set; } } public class D : B { public string More { get; set; } } [KnownType(typeof(D))] public class X { public B[] Col { get; set; } }
我想自动读/写XML,如下所示:
<X> <Col> <B Some="val1" /> <D Some="val2" More="val3" /> </Col> </X>
XmlSerializer和DataContractSerializer都没有帮助我.此XML结构是必需的.
所以问题是:这可以实现,还是我必须手动解析XML?
谢谢,
安德烈
public class X { [XmlArrayItem(typeof(D)), XmlArrayItem(typeof(B))] public B[] Col { get; set; } }