How to add XmlInclude attribute dynamically
问题 I have the following classes [XmlRoot] public class AList { public List<B> ListOfBs {get; set;} } public class B { public string BaseProperty {get; set;} } public class C : B { public string SomeProperty {get; set;} } public class Main { public static void Main(string[] args) { var aList = new AList(); aList.ListOfBs = new List<B>(); var c = new C { BaseProperty = \"Base\", SomeProperty = \"Some\" }; aList.ListOfBs.Add(c); var type = typeof (AList); var serializer = new XmlSerializer(type);