I have this C# 4.0 type
public class DecimalField
{
public decimal Value { get; set; }
public bool Estimate { get; set; }
}
I want to use XmlSerializer to serialize the type into
<Val Estimate="true">123</Val>
Ideally, I want to omit the Estimate attribute if its value is false. Changing Estimate to a nullable bool is acceptable.
What attributes/implementations are required to go from this type to this XML representation?
Thanks.
This is about as close as you can get (an Estimate attribute is always included) without implementing IXmlSerializable:
With IXmlSerializable, your class looks like this:
You can test your class like this: