Попробуйте
[XmlArray]
[XmlArrayItem(ElementName="ABCFile", Type=typeof(ABCFile))]
[XmlArrayItem(ElementName="XYZFile", Type=typeof(XYZFile))]
public List<InputFile> InputFileList
{
get;
set;
}
Это будет указывать сериализатору, что, хотя это и есть список InputFile, в этом списке будут храниться два производных типа. Скорее всего, он будет использовать конкретные версии методов для каждого.
Если не получится, дайте мне знать.
Редактировать на основе вашего комментария
Я не понимаю, как это может происходить.
Я тестировал следующие классы:
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<InputFile>();
}
[XmlArray]
[XmlArrayItem(ElementName = "ABCFile", Type = typeof(ABCFile))]
[XmlArrayItem(ElementName = "XYZFile", Type = typeof(XYZFile))]
public List<InputFile> InputFileList { get; set; }
}
Моя основная программа выглядит так:
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());
}
И, наконец, содержимое serializedString:
<?xml version="1.0"?>
<InputFileHolder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<InputFileList>
<ABCFile>
<InputfileCommonProperty>This is a common property</InputfileCommonProperty>
<ABCSpecificProperty>This is a class specific property</ABCSpecificProperty>
</ABCFile>
</InputFileList>
</InputFileHolder>
Видишь? Сериализатор знает, что это ABCFile, а не универсальный InputFile.