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

    public class CustomStyleHelper
        {

            public static void DoSerialize(string strFile,CustomStyle customstyle)
            {
                using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate))
                {
                    XmlSerializer formatter = new XmlSerializer(typeof(CustomStyle));
                    formatter.Serialize(fs, customstyle);
                }
     
            }
            public static CustomStyle DeSerialize(string strFile)
            {
                CustomStyle customstyle;
                using (FileStream fs = new FileStream(strFile, FileMode.Open))
                {
                    XmlSerializer formatter = new XmlSerializer(typeof(CustomStyle));
                    customstyle = (CustomStyle)formatter.Deserialize(fs);
                }
                return customstyle;
     
            }

            //XML序列化方式不能序列化对象类型属性(比如Color),只能序列化int string类型属性
            //Binary序列化方式可以序列化对象类型属性(比如Color),也能序列化int string类型属性
            //zhangjun 2010.12.10
            public static void BinaryDoSerialize(string strFile, CustomStyle customstyle)
            {
                using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(fs, customstyle);
                }

            }
            public static CustomStyle BinaryDeSerialize(string strFile)
            {
                CustomStyle customstyle;
                using (FileStream fs = new FileStream(strFile, FileMode.Open))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    customstyle = (CustomStyle)formatter.Deserialize(fs);
                }
                return customstyle;

            }

            public static IRgbColor Color2RgbColor(Color color)
            {

                IRgbColor NewColor = new RgbColor();
                NewColor.Blue = color.B;
                NewColor.Red = color.R;
                NewColor.Green = color.G;

                if (color.Name.ToUpper() == "TRANSPARENT")
                {
                    NewColor.Transparency = 0;
                }

                return NewColor;
            }




        }

        [Serializable]
        public class CustomStyle
        {
            private Color sColor;
            public Color SColor
            {
                get { return sColor; }
                set { sColor = value; }
            }

            private double sWidth;
            public double SWidth
            {
                get { return sWidth; }
                set { sWidth = value; }
            }

            private Color dColor;
            public Color DColor
            {
                get { return dColor; }
                set { dColor = value; }
            }

            private double dWidth;
            public double DWidth
            {
                get { return dWidth; }
                set { dWidth = value; }
            }



        }
  • 相关阅读:
    浏览器后台报错,Vue组件的坑:property or method " " is not defined on the instance but referenced during render.Make sure that this property in reactive,either in the data,or for class-based
    去掉iview Modal组件中的取消和确定按钮
    vue实现不刷新整个页面刷新数据
    webstorm永久激活码
    文字过长设置隐藏,鼠标hover时显示在title上
    图片与Base64的转换
    iview的poptip插件,自动换行与自定义content的内容
    RTL基本知识:阻塞赋值与非阻塞赋值
    RTL基本知识:线网或变量宽度与端口宽度不匹配
    RTL基本知识:敏感信号列表中的数组
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1902353.html
Copyright © 2011-2022 走看看