title: Custom Serialization using XmlSerializer
body: <p>I have a class that I need to do some custom XML output from, thus I implement the IXmlSerializable interface. However, some of the fields I want to output with the default serialization except I want to change the xml tag names. When I call serializer.Serialize, I get default tag names in the XML. Can I change these somehow?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class myClass: IXmlSerializable
  {
      //Some fields here that I do the custom serializing on
      ...
  
      // These fields I want the default serialization on except for tag names
      public string[] BatchId { get; set; }
      ...
  
      ... ReadXml and GetSchema methods are here ...
  
      public void WriteXml(XmlWriter writer)
      {                        
          XmlSerializer serializer = new XmlSerializer(typeof(string[]));
          serializer.Serialize(writer, BatchId);
          ... same for the other fields ...
  
          // This method does my custom xml stuff
          writeCustomXml(writer);   
      }
  
      // My custom xml method is here and works fine
      ...
  }
  </code></pre>
  
  <p>Here is my Xml output:</p>
  
  <pre><code>  &lt;MyClass&gt;
      &lt;ArrayOfString&gt;
        &lt;string&gt;2643-15-17&lt;/string&gt;
        &lt;string&gt;2642-15-17&lt;/string&gt;
        ...
      &lt;/ArrayOfString&gt;
      ... My custom Xml that is correct ..
    &lt;/MyClass&gt;
  </code></pre>
  
  <p>What I want to end up with is:</p>
  
  <pre><code>  &lt;MyClass&gt;
      &lt;BatchId&gt;
        &lt;id&gt;2643-15-17&lt;/id&gt;
        &lt;id&gt;2642-15-17&lt;/id&gt;
        ...
      &lt;/BatchId&gt;
      ... My custom Xml that is correct ..
    &lt;/MyClass&gt;
  </code></pre>