zoukankan      html  css  js  c++  java
  • 序列化

            }

            #endregion

     

            #region SoapFormatter序列化

            /// <summary>

            /// SoapFormatter序列化

            /// 必须类型必须标记为Serializable

            /// </summary>

            /// <param name="obj"></param>

            /// <returns></returns>

            public static string SerializeSoapFormatter(object obj)

            {

                SoapFormatter formatter = new SoapFormatter();

                using (MemoryStream ms = new MemoryStream())

                {

                    formatter.Serialize(ms, obj);

                    byte[] bytes = ms.ToArray();

                    return Encoding.UTF8.GetString(bytes);

                }

            }

            /// <summary>

            /// SoapFormatter反序列化

            /// 必须类型必须标记为Serializable

            /// </summary>

            /// <param name="serializedStr"></param>

            /// <returns></returns>

            public static T DeserializeSoapFormatter<T>(string serializedStr)

            {

                SoapFormatter formatter = new SoapFormatter();

                using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(serializedStr)))

                {

                    return (T)formatter.Deserialize(ms);

                }

            }

            #endregion

  • 相关阅读:
    uniapp 小程序分享功能
    uniapp 输入有值后按钮变色
    css 跑马灯
    uniapp 复选框问题
    【Python】where cut query melt函数用法
    【Python】Pivot_table透视表用法及CategoricalDtype自定义排序
    【Python】Merge函数的用法
    【Python】extract及contains方法(正则提取筛选数据)
    Promise
    CSS垂直居中的方法
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/3803052.html
Copyright © 2011-2022 走看看