Save To serialized Object - CSharp System.Xml

CSharp examples for System.Xml:XML Serialization

Description

Save To serialized Object

Demo Code


using System.Xml.Serialization;
using System.Xml.Linq;
using System.IO;//w  w  w.  jav  a  2  s .co m

public class Main{
        public static void SaveTo(object data, StreamWriter writer)
        {
            var serializer = new XmlSerializer(data.GetType());
            serializer.Serialize(writer, data);
        }
        public static void SaveTo(object data, string path)
        {
            var writer = File.CreateText(path);
            SaveTo(data, writer);
        }
}

Related Tutorials