首页 > 其他 > 详细

配置文件序列化到文件中

时间:2015-12-27 00:59:04      阅读:345      评论:0      收藏:0      [点我收藏+]
public class SerializeHelper
    {
        public static bool Serialize(Object data, string fileName)
        {

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Create))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(fs, data);
                }

                return true;
            }
            catch (Exception e)
            {
                return false;
            }


        }

        public static bool Deserialize(string fileName, ref object o)
        {
            try
            {
                if (System.IO.File.Exists(fileName))
                {
                    using (FileStream fs = new FileStream(fileName, FileMode.Open))
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        o = bf.Deserialize(fs);
                    }

                }
                return true;
            }
            catch (Exception e)
            {

                return false;
            }

        }
    }
 var a = SerializeHelper.Serialize(tokenResponse, "token.bin");
                object o = new object(); ;
                var b = SerializeHelper.Deserialize("token.bin", ref o);
                TokenResponseModel t = o as TokenResponseModel;

 

配置文件序列化到文件中

原文:http://www.cnblogs.com/tgdjw/p/5079389.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!