C# serialize decimal to xml

前端 未结 2 883
情深已故
情深已故 2021-02-18 14:01

I got a decimal property, like

[XmlElementAttribute(DataType = \"decimal\")] decimal Price

The problem is that I wanna force it to serialize always

2条回答
  •  感情败类
    2021-02-18 14:50

    You could add XmlIgnore to the actual decimal property and introduce a new property PriceAsString which returns, eh, the price as string (in 10.50 format).

    You could of course also implement IXmlSerializable and do everything yourself.

    However, none of these ways really rocks, and you already stated you were not going to go down this road anyway...

提交回复
热议问题