title: Data Contract Serializer - How to omit the outer element of a collection
body: <p><strong>How do I serialize a list without the outer element</strong> using the Data Contract Serializer?  I am using .Net 3.5.  I have a class that contains a list, amongst other things, that I wish to serialize without the outer element to be compliant with the pertinent XSD:</p>
  
  <pre><code>[DataContract(Name="MyClass")]
  public class MyClass
  {
  ...
  [DataMember(Name="Parameters")]
  public List&lt;Parameter&gt; Parameters;
  ...
  }
  
  [DataContract(Name="Parameter")]
  public struct Parameter
  {
      [DataMember(Name="ValueName")]string ValueName;
      [DataMember(Name="Value")]int Value;
      public Parameter(string ValueName, int Value)
      {
          this.ValueName = ValueName;
          this.Value = Value;            
      }
  }
  </code></pre>
  
  <p>The above serializes as (assuming only one Parameter in the list):</p>
  
  <pre><code>&lt;MyClass&gt;
      &lt;Parameters&gt;
         &lt;Parameter&gt;
             &lt;ValueName&gt;&lt;/ValueName&gt;
             &lt;Value&gt;&lt;/Value&gt;
         &lt;/Parameter&gt;
      &lt;/Parameters&gt;
  &lt;/MyClass&gt;
  </code></pre>
  
  <p>I would like to serialize it as follows:</p>
  
  <pre><code>&lt;MyClass&gt; 
         &lt;Parameter&gt;
             &lt;ValueName&gt;&lt;/ValueName&gt;
             &lt;Value&gt;&lt;/Value&gt;
         &lt;/Parameter&gt;
  &lt;/MyClass&gt;
  </code></pre>
  
  <p>Using the XmlSerializer I can do this by applying the [XmlElement] to the list:</p>
  
  <pre><code>[XmlElement ("Parameter")]
  public List&lt;Parameter&gt; Parameters;
  </code></pre>
  
  <p>However I do not want to use the <code>XmlSerializer</code> because my class has a few properties that are not serialization friendly and I was hoping to deal with those using the [OnSerializing] family of attributes.</p>
  
  <p>Thanks.</p>