【发布时间】:2009-07-15 14:18:45
【问题描述】:
我一直在阅读,但我没有找到解决问题的方法
我目前正在使用一个包含我所有数据的业务对象,我们需要将此对象与 XML 相互转换。
我的对象包含一个动作列表(列表...),但有 2 种动作类型(目前)。 我必须操作类型 SimpleAction 和 CompositeAction,它们都从 IAction 继承,允许它们都保存在 Actions 列表中。
现在您可能会看到问题,因为接口无法序列化,因为它们没有数据。
如何使用一些示例代码编写一个获取该对象类型并执行然后序列化具有正确类型的对象的类或序列化程序?
一些代码:
[XmlArray("Actions")]
public List<IAction> Actions { get; set; }
public interface IAction
{
int ID { get; set; }
ParameterCollection Parameters { get; set; }
List<SectionEntity> Validation { get; set; }
TestResultEntity Result { get; set; }
string Exception { get; set; }
}
[XmlType("A")]
public class SimpleActionEntity : IAction
{
#region IAction Members
[XmlAttribute("ID")]
public int ID { get; set; }
[XmlIgnore]
public ParameterCollection Parameters { get; set; }
[XmlIgnore]
public List<SectionEntity> Validation { get; set; }
[XmlIgnore]
public TestResultEntity Result { get; set; }
[XmlElement("Exception")]
public string Exception { get; set; }
#endregion
}
任何帮助将不胜感激。 :)
【问题讨论】:
标签: c# xml serialization