title: Tweak output from XmlSerializer in C#
body: <p>I am wondering if there is a way to get XmlSerializer in C# to change what it outputs for one property of one object.  For example, if I have something like:</p>
  
  <pre><code>public class MyClass
  {
      public string prop1{get;}
      public uint prop2{get;}
      public MyClass2 class2{get;}
      public MyClass3 class3{get;}
  }
  
  public class MyClass2
  {
      public string prop3{get;}
  }
  
  public class MyClass3
  {
      //Lots of properties that I want to serialize as normal
  }
  </code></pre>
  
  <p>Now in somewhere in my code, I have something like this:</p>
  
  <pre><code>private void SerializeStuff(List&lt;MyClass&gt; list, string path)
  {
      XmlSerializer serialize = new XmlSerializer(typeof(List&lt;MyClass&gt;));
      TextWriter writer = new StreamWriter(path);
      serialize.Serialize(writer, list);
      writer.Close();
  }
  </code></pre>
  
  <p>What I want is for the serialization to work as normal, but with <code>prop3</code> replaced with some other stuff.  Example:</p>
  
  <pre><code>&lt;MyClass&gt;
      &lt;prop1&gt;whatever&lt;/prop1&gt;
      &lt;prop2&gt;345&lt;/prop2&gt;
      &lt;class2&gt;
          &lt;somethingNotProp3&gt;whatever&lt;/somethingNotProp3&gt;
          &lt;somethingElseNotProp3&gt;whatever&lt;/somethingElseNotProp3&gt;
      &lt;/class2&gt;
      &lt;class3&gt;
          ...
      &lt;/class3&gt;
  &lt;/MyClass&gt;
  </code></pre>
  
  <p>Is there a way to customize XmlSerializer so I don't have to write the entire Xml file manually, or is there no way to do that?</p>
  
  <p>Edit:
  I am pretty sure that the solution could have something to do with implementing <code>ISerializable</code>'s <code>GetObjectData</code> method; however, I am not exactly sure how to implement it.  I tried making <code>MyClass2</code> inherit from <code>ISerializable</code> and implementing <code>GetObjectData</code>, but nothing changed. <code>prop3</code> was still output in the XML file.</p>