title: XML Serialization and empty collections
body: <p>I have a a property defined as:</p>
  
  <pre><code>[XmlArray("delete", IsNullable = true)]
  [XmlArrayItem("contact", typeof(ContactEvent)),
   XmlArrayItem("sms", typeof(SmsEvent))]
  public List&lt;Event&gt; Delete { get; set; }
  </code></pre>
  
  <p>If the List&lt;> Delete has no items</p>
  
  <pre><code>&lt;delete /&gt;
  </code></pre>
  
  <p>is emitted. If the List&lt;> Delete is set to null</p>
  
  <pre><code>&lt;delete xsi:nil="true" /&gt;
  </code></pre>
  
  <p>is emitted. Is there a way using attributes to get the delete element not to be emitted if the collection has no items?</p>
  
  <p><a href="https://stackoverflow.com/questions/69296/xml-serialization-and-empty-collections#69407">Greg</a> - Perfect thanks, I didn't even read the IsNullable documentation just assumed it was signalling it as not required.</p>
  
  <p><a href="https://stackoverflow.com/questions/69296/xml-serialization-and-empty-collections#69518">Rob Cooper</a> - I was trying to avoid ISerializable, but Gregs suggestion works. I did run into the problem you outlined in (1), I broke a bunch of code by just returning null if the collection was zero length. To get around this I created a EventsBuilder class (the class I am serializing is called Events) that managed all the lifetime/creation of the underlying objects of the Events class that spits our Events classes for serialization.</p>