/// <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; }
时间: 2024-10-24 06:04:25