Object to XML String - 对象的属性不包含在XML字符串中

时间:2014-07-12 00:11:21

标签: c# xml xml-serialization

我正在将以下的ListingRequest对象转换为XML字符串。然而,"皮卡"类ListRequest的属性和类ShippingOption的Type属性未包含在XML字符串中。

代码:

  ListingRequest s = new ListingRequest()
        {
            Pickup = PickupOptions.Allow,
            Category = "0124-0126-4592-",
            Title = "Cricket Bat",
            Description = new string[] { "This is a cricket bat", "Bat." },
            StartPrice = 20,
            BuyNowPrice = 20,
            Duration = ListingDuration.Five,
            ShippingOptions =
            new ShippingOption[]{new ShippingOption {Type = ShippingType.Free,
            Price = 77,
            Method = "Ruler delivery"}}
        };

            string xml = SerializeToString(s);

注意:ListingRequest对象的Pickup属性和ShippingOption对象的Type属性不包含在XML字符串中。

可以在架构中找到ListingRequest和送货选项对象 here

这是SerializeToString()方法

 public static string SerializeToString(object obj)
        {
            XmlSerializer serializer = new XmlSerializer(obj.GetType());

            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, obj);

                return writer.ToString();
            }
        }

0 个答案:

没有答案