2

I have a draw class and there is where I declared

    public List<Layers> layers = new List<Layers>();

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 error reflecting type layers.

public class Draw
{
    [XmlIgnore]
    public Shape s = new Shape();
    [XmlIgnore]
    public ImageClass img = new ImageClass();
    public List<Layers> layers = new List<Layers>();
}

Layer Class

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; } }
}

Serialization Method

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);
        }
    }
TerribleDog
  • 1,237
  • 1
  • 8
  • 31
  • Can you provide the definition for `Layers` and the serialization code? And when you say "declared in another class", do you mean a [nested class](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/nested-types)? – ProgrammingLlama Oct 23 '18 at 01:24
  • @John edited the code. I didn't use nested class. – TerribleDog Oct 23 '18 at 01:26
  • "list of a class declared in another class?" - I assume you meant defined in _another file_ then? – ProgrammingLlama Oct 23 '18 at 01:29
  • No i meant, serializing the Draw class, where a list of another class is declared and gets its properties. – TerribleDog Oct 23 '18 at 01:41
  • @untargeted, could u plz add details of error did u faced? – er-sho Oct 23 '18 at 06:18
  • @ershoaib I did not face an error, I am asking a 'how to' – TerribleDog Oct 23 '18 at 07:03
  • @untargeted, u wrote this in your post => `Draw Class but it gives an error reflecting type layers.` so that why m ask u to provide error. anyways so `Serialization` method cant serialize your xml properly right? – er-sho Oct 23 '18 at 07:07
  • @ershoaib Thanks, an I'm sorry. I already fixed the problem. Maybe you can help me with another one, – TerribleDog Oct 23 '18 at 07:21
  • https://stackoverflow.com/questions/52943319/resolution-is-broken-when-converting-byte-to-image @ershoaib – TerribleDog Oct 23 '18 at 07:23

0 Answers0