using System.IO; using System.Xml.Serialization; namespace PdmSwPlugin.Common.Util.Xml { public static class XmlUtil { public static bool WriteToXml(string path, object obj) { XmlSerializer serializer = new XmlSerializer(obj.GetType()); string content = string.Empty; using (StringWriter writer = new StringWriter()) { serializer.Serialize(writer, obj); content = writer.ToString(); } using (StreamWriter stream_writer = new StreamWriter(path)) { stream_writer.Write(content); } return true; } public static T ReadFromXml(string path) { XmlSerializer serializer = new XmlSerializer(typeof(T)); using (StreamReader reader = new StreamReader(path)) { return (T)serializer.Deserialize(reader); } } } }