码迷,mamicode.com
首页 > Web开发 > 详细

Silverlight中的序列化和反序列化

时间:2015-03-20 18:14:18      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

  /// <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;
        }

 

Silverlight中的序列化和反序列化

标签:

原文地址:http://www.cnblogs.com/mrcui/p/4354105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!