title: How to serialize a class that contains objects of other classes (recursive serializing?)
body: <p>How can I do this? Or will the serializer automatically go with recursion, and serialize all those child objects into XML?</p>
  
  <p><strong>Give me an example how would you serialize classes that contain other classes' objects in themselves! That was the core of this question!</strong></p>
  
  <p>I've tried this, and it didn't output <strong>anything</strong> (except the XML header) to the targeted XML file.</p>
  
  <p>My problem is that I need to serialize a simple class, that just holds a List object. But, those Entities also hod List objects. (Another plus would be if I could avoid the serialization of some components, because some are derived and have dictionaries in them).</p>
  
  <pre><code>public void SaveCurrent(string MapFileName)
  {
      string MapPath = world_.game_.Content.RootDirectory + "/Maps/" + MapFileName + ".xml";
      StreamWriter MapWriter = new StreamWriter(MapPath);
  
      Map SavedMap = new Map();
      SavedMap.Entities = world_.Entities;
      XmlSerializer xSerializer = new XmlSerializer(SavedMap.GetType());
  
      xSerializer.Serialize(MapWriter, SavedMap);
      MapWriter.Close();
  }
  </code></pre>
  
  <p>That's the piece of code that does the serialization.</p>
  
  <pre><code>public class Map
  {
      internal string MapName;
      internal string MapDescription;
      internal string MapAuthor;
      public List&lt;Entity&gt; Entities = new List&lt;Entity&gt;();
  }
  </code></pre>
  
  <p>And this is the class that's serialized. <strike>Could internals be counted as publics, if the serialization is called from the same assembly?</strike> The code throws exception at the <code>SavedMap.GetType()</code> function, and I've tried <code>typeof(Map)</code> too, but without success. I guess it's because I need some other way to handle each new class (deep serialization) how do I do that?</p>
  
  <p>Also, I've found on some examples, that there are no interface inheritance or attributes, therefore I didn't add those either, but I'm planning to use IXmlSerializable, though I don't know how to call another serialization inside WriteXML implementation.</p>