Serialize an object to XML

后端 未结 17 1901
渐次进展
渐次进展 2020-11-22 04:41

I have a C# class that I have inherited. I have successfully \"built\" the object. But I need to serialize the object to XML. Is there an easy way to do it?

It looks

17条回答
  •  情深已故
    2020-11-22 05:31

    Or you can add this method to your object:

        public void Save(string filename)
        {
            var ser = new XmlSerializer(this.GetType());
            using (var stream = new FileStream(filename, FileMode.Create))
                ser.Serialize(stream, this);
        }
    

提交回复
热议问题