I have a class which is used for Xml Serialization.
Inside which I have a nullable property which is decorated with XmlAttribute:
[XmlAttribute("lastUpdated")]
public DateTime? LastUpdated { get; set; }
How to ignore the property from serialization if it is null or empty?
I've tried the below but it doesn't serialize when there is a value (always ignores):
[XmlIgnore]
public DateTime? LastUpdatedValue { get; set; }
[XmlAttribute("lastUpdated")]
public DateTime LastUpdated { get; set; }
public bool ShouldSerializeLastUpdated()
{
return LastUpdatedValue.HasValue;
}