Note that there are some explanatory texts on larger screens.

plurals
  1. POSerializing a List hold an interface to XML
    text
    copied!<p>I have been reading around but I have not come across a solution to my problem</p> <p>I am currently working with a Business Object that will hold all my data and we need to convert this object to and from XML.</p> <p>My object holds a list of Actions (List...), but there are 2 action types (for now). I have to action types SimpleAction and CompositeAction, and they both inherit from IAction allowing them to both be held in the Actions list.</p> <p>Now you can probably see the problem as Interfaces cannot be serialized as they hold no data. </p> <p>How, with maybe some sample code, do I write a Class or Serializer that gets that object type and performs then serializes object with the correct type?</p> <p>Some code:</p> <pre><code> [XmlArray("Actions")] public List&lt;IAction&gt; Actions { get; set; } public interface IAction { int ID { get; set; } ParameterCollection Parameters { get; set; } List&lt;SectionEntity&gt; 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&lt;SectionEntity&gt; Validation { get; set; } [XmlIgnore] public TestResultEntity Result { get; set; } [XmlElement("Exception")] public string Exception { get; set; } #endregion } </code></pre> <p>Any help would be greatly appreciated. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload