/// <summary> /// 序列化 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static byte[] SerializeObject<T>(T obj) where T : class { System.IO.MemoryStream stream = new System.IO.MemoryStream(); XmlSerializer xmlSer = new XmlSerializer(obj.GetType()); xmlSer.Serialize(stream, obj); byte[] Buffer = stream.GetBuffer(); stream.Close(); return Buffer; } /// <summary> /// 反序列化 /// </summary> /// <param name="Buffer"></param> /// <returns></returns> public static T DeSerialize<T>(byte[] Buffer) where T : class { System.IO.MemoryStream stream = new System.IO.MemoryStream(Buffer); XmlSerializer xmlSer = new XmlSerializer(typeof(T)); T obj = xmlSer.Deserialize(stream) as T; stream.Close(); return obj; }