有一个错误反映了System.Collections.Generic.List`类型

时间:2014-06-04 17:20:01

标签: c# wpf list xml-serialization

我需要在我的学习项目中保存到文件序列化对象列表。我第一次使用序列化。我阅读了很多例子,但我无法解决我的错误。我收到错误'有一个错误反映了类型' System.Collections.Generic.List`' 这是我要序列化的课程

namespace projekt2
{
    [Serializable()]
    public class wezel : ICloneable
    {
        public Label text {get;set;}
        public Ellipse el {get;set;}
        public int id {get;set;}
        public wezel(Label text, Ellipse el, int id)
        {
            this.text = text;
            this.el = el;
            this.id = id;
        }
        public wezel()
        {
        }
        public object Clone()
        {
            return this.MemberwiseClone();
        }

    }
}

列表声明

public List <wezel> w= new List<wezel>();

并尝试序列化

public void SerializeToXML(MainWindow window, Canvas canvas, int dpi, string filename)
        {
            string mystrXAML = XamlWriter.Save(canvas);
            FileStream filestream = File.Create(filename);
            StreamWriter streamwriter = new StreamWriter(filestream);
            streamwriter.Write(mystrXAML);
            streamwriter.Close();
            filestream.Close();
            XmlSerializer serializer = new XmlSerializer(typeof(List<wezel>)); 
            TextWriter textWriter = new StreamWriter(@"wezly.xml");
            serializer.Serialize(textWriter, w);
            textWriter.Close(); 
        }

现在有人可以解决这个错误并序列化这个对象wezel列表吗?

0 个答案:

没有答案