zoukankan      html  css  js  c++  java
  • 序列化 和 反序列化 类

    public class Formater
        {
            public static byte[] Serialize(Object _object)
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
              
                binaryFormatter.Serialize(ms, _object);
              
                ms.Position = 0;
              
                byte[] b;
                b = new Byte[ms.Length];
                ms.Read(b, 0, b.Length);
                ms.Close();
                return b;
            }
            public static Object Deserialize(byte[] serializes)
            {
                Object obj = new object();
                if (serializes.Length == 0) return null;
                try
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    MemoryStream ms = new MemoryStream();
                    ms.Write(serializes, 0, serializes.Length);
                    ms.Position = 0;

                    obj = binaryFormatter.Deserialize(ms);
                    ms.Close();
                }
                catch
                {
                    obj = null;
                }
                return obj;
            }
        }

  • 相关阅读:
    PHP使用Redis的GEO地理信息类型
    Redis长短链接的区别
    Linux之ln文件创建链接
    xml与json格式互转
    爬虫实例:唐诗宋词爬虫
    爬虫实例:天猫商品评论爬虫
    爬虫实例:饿了么爬虫
    爬虫实例:中国日报高频词汇爬虫
    爬虫实例:今日头条爬虫
    特殊类型的列表切片
  • 原文地址:https://www.cnblogs.com/zlddtt/p/1544230.html
Copyright © 2011-2022 走看看