title: DataContractSerializer for an inline array
body: <p>I need to serialize and deserialize the following XML for a Windows app (it is an existing API, already handled fine by iOS and Android apps). Please note the multiple items:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;parameters&gt;
    &lt;source&gt;home&lt;/source&gt;
    &lt;day&gt;today&lt;/day&gt;
    &lt;item&gt;&lt;name&gt;foo&lt;/name&gt;&lt;/item&gt;
    &lt;item&gt;&lt;name&gt;bar&lt;/name&gt;&lt;/item&gt;
    &lt;item&gt;&lt;name&gt;baz&lt;/name&gt;&lt;/item&gt;
  &lt;/parameters&gt;
  </code></pre>
  
  <p>So I made this class:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[DataContract(Name = "parameters", Namespace = "")]
  internal class Parameters
  {
      [DataMember(Name = "source", EmitDefaultValue = false, Order = 0)]
      public string Source;
  
      [DataMember(Name = "day", EmitDefaultValue = false, Order = 1)]
      public string Day;
  
      [DataMember(Name = "item", EmitDefaultValue = false, Order = 2)]
      public Item[] Items;
  }
  
  [DataContract(Name = "item", Namespace = "")]
  internal class Item
  {
      [DataMember(Name = "name", EmitDefaultValue = false, Order = 0)]
      public string Name;
  }
  </code></pre>
  
  <p>My code with <code>DataContractSerializer</code> is:</p>
  
  <pre><code>// Serialization:
  using (var streamObject = new MemoryStream())
  using (var reader = new StreamReader(streamObject))
  {
      var ser = new DataContractSerializer(typeof(T));
      ser.WriteObject(streamObject, objForSerialization);
      streamObject.Position = 0;
      return reader.ReadToEnd();
  }
  
  [...]
  
  // Deserialization:
  using (var streamObject = new MemoryStream(Encoding.UTF8.GetBytes(xmlData)))
  {
      var ser = new DataContractSerializer(typeof(T));
      return (T)ser.ReadObject(streamObject);
  }
  </code></pre>
  
  <p>But the resulting serialization is not what I need:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;parameters&gt;
    &lt;source&gt;home&lt;/source&gt;
    &lt;day&gt;today&lt;/day&gt;
    &lt;item&gt;
      &lt;item&gt;&lt;name&gt;foo&lt;/name&gt;&lt;/item&gt;
      &lt;item&gt;&lt;name&gt;bar&lt;/name&gt;&lt;/item&gt;
      &lt;item&gt;&lt;name&gt;baz&lt;/name&gt;&lt;/item&gt;
    &lt;/item&gt;
  &lt;/parameters&gt;
  </code></pre>
  
  <p>And it won't let me deserialize the first example!</p>