title: C# serialize private class member
body: <pre><code>class Person
  {
      public string m_name;
      private int m_age; // &lt;&lt; how do I serialize the darn little rat?
  }
  </code></pre>
  
  <p>Simple question yet it seems like a big mess when trying to answer it.<br>
  Everyone suggest to use public getter/setter but my app is too big and making a getter/setter for each member would just cause maintainability issues.</p>
  
  <p>Am I forced to create a custom serialization here or is there a magic attribute for such members?<br>
  How do I serialize private class members?</p>
  
  <p><strong>Edit #1</strong>:<br>
  Ok everyone, sorry for the unclarity, I was a bit upset when I wrote this question, it was several hours after trying to find the solution.<br>
  Anyway, here are more facts:<br>
   1. I'm trying to XML serialize this class. <strong>Currently I'm using <code>System.Xml.Serialization.XmlSerializer</code>.</strong><br>
   2. I'm <strong>serializing into XML to have version compatibility</strong>, which as far as I understand binary doesn't offer me that.<br>
   3.I was hoping that there's a certain <strong>attribute like</strong>:</p>
  
  <pre><code>class Person
  {
      public string m_name;
      [SerializeThat(ElementName="Age")]
      private int m_age; // &lt;&lt; how do I serialize the darn little rat?
  }
  </code></pre>
  
  <p><strong>OR</strong> (continue of fact #3) an <strong>attribute that goes on the class</strong> which would look like:</p>
  
  <pre><code>[Serializable(DoPrivate = true, DoProtected = true)]
  class Person
  {
      public string m_name;
      private int m_age; // &lt;&lt; how do I serialize the darn little rat?
  }
  </code></pre>
  
  <p>Now, what can I do to achieve it?</p>