Serializing an array of multiple types using XmlSerializer

后端 未结 3 859
慢半拍i
慢半拍i 2020-12-11 13:47

I\'m trying to use XMLSerializer to generate XML such as the following, where the contents of is an array, but the elements can be of differing t

3条回答
  •  悲哀的现实
    2020-12-11 14:12

    In your c# class, just make sure you always return an empty array of any possible types that might be returned:

        [Serializable]
    public class create
    {
        public create()
        {
            vendor = new Vendor[0];
            customer = new Customer[0];
            asset = new Asset[0];
        }
        Vendor[] vendor { get; set; }
        Customer[] customer { get; set; }
        Asset[] asset { get; set; }
    }
    [Serializable]
    public class Vendor
    {
        public string vendorid { get; set; }
        public string name { get; set; }
        public string vcf_bill_siteid3 { get; set; }
    }
    [Serializable]
    public class Customer
    {
        public string CUSTOMERID { get; set; }
        public string NAME { get; set; }
    }
    [Serializable]
    public class Asset
    {
        public string createdAt { get; set; }
        public string createdBy { get; set; }
        public string serial_number { get; set; }
    }
    

提交回复
热议问题