As you have discovered yourself Nullable<T>
doesn't just work with [XmlAttribute]
as it's a complex type. You'll have to use the 'magic' property *Specified to deal with this.
[XmlIgnore]
public float? RelativeX
{
get { return this.RelativeX; }
set { this.RelativeX = value; }
}
[XmlAttribute("RelativeX")]
public float RelativeXValue
{
get { return this.RelativeX.Value; }
set { this.RelativeX = value; }
}
[XmlIgnore]
public bool RelativeXValueSpecified
{
get { return this.RelativeX.HasValue; }
}
Your other options are:
- Use strings for all of your attributes and have corresponding properties of the right type
- Implement
IXmlSerializable