title: How do I serialize a list of a class declared in another class?
body: <p>I have a draw class and there is where I declared </p>
  
  <pre><code>    public List&lt;Layers&gt; layers = new List&lt;Layers&gt;();
  </code></pre>
  
  <p>as a list of my layer class. Now what I want to do is to serialize into Xml the Draw Class but it gives an <em>error reflecting type layers</em>.</p>
  
  <pre><code>public class Draw
  {
      [XmlIgnore]
      public Shape s = new Shape();
      [XmlIgnore]
      public ImageClass img = new ImageClass();
      public List&lt;Layers&gt; layers = new List&lt;Layers&gt;();
  }
  </code></pre>
  
  <p><strong>Layer Class</strong></p>
  
  <pre><code>public class Layers
  {
      public ImageClass _image { get; set; }
      public Shape _shape { get; set; }
      public enum Type { Rectangle, Square, Circle, Ellipse, Triangle, Image }
      public Layers.Type type { get; set; }
      public float width { get; set; }
      public float height { get; set; }
      public PointF location { get; set;}
      public int radius { get; set; }
      public int strokeThickness { get; set; }
      public Color color { get; set; }
      public Bitmap image { get; set; }
      public RectangleF rect { get; set; }
      public PointF centerSerializable { get { return Shape.center; } set { Shape.center = value; } }
  }
  </code></pre>
  
  <p><strong>Serialization Method</strong></p>
  
  <pre><code>public void Serialization()
      {
          try
          {
              XmlSerializer ser = new XmlSerializer(typeof(Draw)); //Serializer
              SaveFileDialog save = new SaveFileDialog();           //Creates and Opens a SaveFileDialog
              save.Filter = "Seal Creator File (*.sealFile)|*.sealFile";     //Creates a filter fir saving the Project File
              save.DefaultExt = ".seal";
              save.AddExtension = true;
  
              if (save.ShowDialog() == DialogResult.OK)
              {
                  //Serialization process for the Class
                  FileStream file = File.Create(save.FileName);
                  ser.Serialize(file, draw);
                  file.Close();
                  MessageBox.Show("Saved"); //Saving Confirmation
              }
          }
          catch (Exception ex)
          {
              //Catching the Error
              String innerMessage = (ex.InnerException != null) ? ex.InnerException.Message : "";
              Debug.WriteLine(innerMessage);
          }
      }
  </code></pre>