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