Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try</p> <pre><code>[XmlArray] [XmlArrayItem(ElementName="ABCFile", Type=typeof(ABCFile))] [XmlArrayItem(ElementName="XYZFile", Type=typeof(XYZFile))] public List&lt;InputFile&gt; InputFileList { get; set; } </code></pre> <p>This will indicate the serializer that, even though this is a List of InputFile, there will be two derived types that will be stored in this list. It's likely to make it use specific version of methods for each one.</p> <p>If it fail, let me know.</p> <p><strong>Edit based on your comment</strong></p> <p>I don't see how this can be happing.</p> <p>I tested it the following classes:</p> <pre><code>public class InputFile { public String InputfileCommonProperty { get; set; } } public class ABCFile : InputFile { public String ABCSpecificProperty { get; set; } } public class XYZFile : InputFile { public String XYZSpecificProperty { get; set; } } public class InputFileHolder { public InputFileHolder() { InputFileList = new List&lt;InputFile&gt;(); } [XmlArray] [XmlArrayItem(ElementName = "ABCFile", Type = typeof(ABCFile))] [XmlArrayItem(ElementName = "XYZFile", Type = typeof(XYZFile))] public List&lt;InputFile&gt; InputFileList { get; set; } } </code></pre> <p>My main program looks like:</p> <pre><code>static void Main(string[] args) { InputFileHolder fileHolder = new InputFileHolder(); fileHolder.InputFileList.Add( new ABCFile() { InputfileCommonProperty = "This is a common property", ABCSpecificProperty = "This is a class specific property" }); XmlSerializer serializer = new XmlSerializer(typeof(InputFileHolder)); MemoryStream memoryStream = new MemoryStream(); serializer.Serialize(memoryStream, fileHolder); System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); String serializedString = enc.GetString(memoryStream.ToArray()); } </code></pre> <p>And in the end, serializedString's content is:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;InputFileHolder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;InputFileList&gt; &lt;ABCFile&gt; &lt;InputfileCommonProperty&gt;This is a common property&lt;/InputfileCommonProperty&gt; &lt;ABCSpecificProperty&gt;This is a class specific property&lt;/ABCSpecificProperty&gt; &lt;/ABCFile&gt; &lt;/InputFileList&gt; &lt;/InputFileHolder&gt; </code></pre> <p>You see? The serializer knows it's a ABCFile not a generic InputFile.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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