public class PubXmlSerializer{ /// /// 實體序列化成xml string /// /// ///public static string ToXMLString(T meta) { DataContractSerializer dcs = new DataContractSerializer(typeof(ActionInfo)); string xmlStr = string.Empty; using (MemoryStream ms = new MemoryStream()) { try { dcs.WriteObject(ms, meta); xmlStr = Encoding.UTF8.GetString(ms.ToArray()); ms.Close(); } catch (Exception ee) { MessageBox.Show(ee.ToString()); } } return xmlStr; } /// /// 實體反序列化 /// /// ///public static T ReadFromXML(string xmlStr) { T meta; DataContractSerializer dcs = new DataContractSerializer(typeof(ActionInfo)); using (TextReader reader = new StringReader(xmlStr)) { using (XmlReader xReader = XmlReader.Create(reader)) { meta = (T)dcs.ReadObject(xReader); } } return meta; } }