title: How to override xml element name for collection elements using XmlAttributeOverrides?
body: <p>I've got a very basic object object model that is being serialized by the System.Xml.XmlSerialization stuff. I need to use the XmlAttributeOverrides functionality to set the xml element names for a collection of child elements.</p>
  
  <pre><code>public class Foo{
    public List Bars {get; set; }
  }
  
  public class Bar {
    public string Widget {get; set; }
  }
  </code></pre>
  
  <p>using the standard xml serializer, this would come out as</p>
  
  <pre><code> &lt;Foo>
    &lt;Bars>
      &lt;Bar>...&lt;/Bar>
    &lt;/Bars>
   &lt;/Foo>
  </code></pre>
  
  <p>I need to use the XmlOverrideAttributes to make this say</p>
  
  <pre><code> &lt;Foo>
    &lt;Bars>
      &lt;SomethingElse>...&lt;/SomethingElse>
    &lt;/Bars>
   &lt;/Foo>
  </code></pre>
  
  <p>but I can't seem to get it to rename the child elements in the collection... i can rename the collection itself... i can rename the root... not sure what i'm doing wrong.</p>
  
  <p>here's the code I have right now:</p>
  
  <pre><code>XmlAttributeOverrides xOver = new XmlAttributeOverrides();
  
  var bars = new XmlElementAttribute("SomethingElse", typeof(Bar));
  var elementNames = new XmlAttributes();
  elementNames.XmlElements.Add(bars);
  xOver.Add(typeof(List), "Bars", elementNames);
  
  StringBuilder stringBuilder = new StringBuilder();
  StringWriter writer = new StringWriter(stringBuilder);
  XmlSerializer serializer = new XmlSerializer(typeof(Foo), xOver);
  serializer.Serialize(writer, someFooInstance);
  
  string xml = stringBuilder.ToString();
  </code></pre>
  
  <p>but this doesn't change the name of the  element at all... what am I doing wrong?</p>
  
  <p>thanks</p>