如何解决XML 序列化中的发送类型
我有通过 XmlSerializer
序列化为 XML 的类:
[System.SerializableAttribute()]
public partial class Coupon
{
private string couponCodeField;
private int quantityField;
public string CouponCode
{
get
{
return this.couponCodeField;
}
set
{
this.couponCodeField = value;
}
}
public int Quantity
{
get
{
return this.quantityField;
}
set
{
this.quantityField = value;
}
}
}
序列化后的输出为:
<Coupon>
<CouponCode>9900000555780</CouponCode>
<Quantity>965</Quantity>
</Coupon>
就我而言,我需要将生成的 XML 中的所有属性类型作为 XML 属性发送。 所以我需要输出看起来像这样:
<Coupon>
<CouponCode type="xs:string">9900000555780</CouponCode>
<Quantity type="xs:integer">965</Quantity>
</Coupon>
有人知道如何在不将每个属性从简单类型更改为类的情况下做到这一点吗?
也许是一些 XmlSerializer
属性?或者一些对所有属性通用的自定义属性?
喜欢
[CustomAttr.TypeSpecify]
public int Quantity
{
get
{
return this.quantityField;
}
set
{
this.quantityField = value;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。