public static string SerializeToXml <T>(T serializableObject, XmlWriterSettings xmlSettings = null) { XtraXmlSerializer serializer = new XtraXmlSerializer(typeof(T)); using (Stream storage = new MemoryStream()) { using (XmlWriter xmlWriter = XmlWriter.Create(storage, xmlSettings ?? new XmlWriterSettings())) { serializer.Serialize(xmlWriter, serializableObject); } storage.Seek(0, SeekOrigin.Begin); using (StreamReader reader = new StreamReader(storage, Encoding.UTF8)) { return(reader.ReadToEnd()); } } }
public static void SaveToXml <T>(String fileName, T serializableObject, XmlWriterSettings xmlSettings = null) { if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } XtraXmlSerializer serializer = new XtraXmlSerializer(typeof(T)); using (TextWriter writer = new StreamWriter(fileName)) { using (XmlWriter xmlWriter = XmlWriter.Create(writer, xmlSettings ?? new XmlWriterSettings() { Indent = true })) { serializer.Serialize(xmlWriter, serializableObject); } } }