using System.IO; using System.Text; using System.Xml; using System.Xml.Serialization; namespace SSWMS.Common { public class XmlConvert { public static T XmlDeserialize(string xml) { using (StringReader sr = new StringReader(xml)) { return (T)new XmlSerializer(typeof(T)).Deserialize(sr); } } public static string XmlSerialize(T t) { using (MemoryStream ms = new MemoryStream()) { new XmlSerializer(typeof(T)).Serialize(new XmlTextWriter(ms, Encoding.UTF8) { Formatting = Formatting.None }, t, new XmlSerializerNamespaces(new XmlQualifiedName[] { new XmlQualifiedName("", "") })); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { return sr.ReadToEnd(); } } } } }