Serialize a nullable int

XmlSerializer supports the ShouldSerialize{Foo}() pattern, so you can add a method:

public bool ShouldSerializeID() {return ID.HasValue;}

There is also the {Foo}Specified pattern – not sure if XmlSerializer supports that one.

Leave a Comment