title: Custom XML serialization for a single property
body: <p>I want to serialize all properties of type string[] as CSV. </p>
  
  <p>For example, given a class:</p>
  
  <pre><code>public class Choice {
      [XmlAttribute]
      public string[] Options { get; set; }
  }
  </code></pre>
  
  <p>and the following serialization code:</p>
  
  <pre><code>var choice = new Choice() { Options = new[] {"op 1", "op 2"}};
  var serializer = new XmlSerializer(typeof(Choice));
  var sb = new StringBuilder();
  serializer.Serialize(new StringWriter(sb), choice);
  Console.WriteLine(sb);
  </code></pre>
  
  <p>I have the following output:</p>
  
  <p><code>&lt;Choice xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Options="op 1 op 2" /&gt;
  </code></p>
  
  <p>Note the <code>Options="op 1 op 2"</code> part. If I deserialize the output, the value is split into 4 strings, giving me 4 array elements instead of 2 that were there originally.</p>
  
  <p>What I want is to be able to run a custom code for this particular property (or for any property of type <code>string[]</code>), so that I control the output. I don't want to override the serialization process for the whole class.</p>
  
  <p>If this is impossible or too hard to implement with the default Microsoft Serializer, I'll be happy to consider a better alternative.</p>