コード例 #1
0
ファイル: Shapes.cs プロジェクト: kerwinxu/barcodeManager
 public Shapes()
 {
     //空白的
     BarcodePageSettings = new ClsPageSettings();
     arrlistKeyValue = new ArrayList();
     arrlistShapeEle = new ArrayList();
 }
コード例 #2
0
        public FrmPageSettings(ClsPageSettings pageSettings)
        {
            InitializeComponent();

            //如下是用序列化深度拷贝一个对象
            #region
            try
            {
                if (pageSettings==null)
                {
                    BarcodePageSettings = new ClsPageSettings();
                }
                else
                {
                    //如下是用内存流来序列化
                    if (true)
                    {
                        using (MemoryStream memory3 = new MemoryStream())
                        {
                            XmlSerializer xs = new XmlSerializer(typeof(ClsPageSettings));

                            xs.Serialize(memory3, pageSettings);//序列化
                            memory3.Seek(0, SeekOrigin.Begin);//移动到开头

                            //反序列化
                            XmlSerializer xs2 = new XmlSerializer(typeof(ClsPageSettings));
                            BarcodePageSettings = xs2.Deserialize(memory3) as ClsPageSettings;//这样就深度拷贝了

                            memory3.Close();//销毁
                        }

                }

                }

                #region  如下的会产生问题,所以注释掉了

                if (false)
                {
                    using (Stream stream = new FileStream(Application.StartupPath + "\\tempPageSettings", FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        //如下是序列化
                        XmlSerializer xmls = new XmlSerializer(typeof(ClsPageSettings));
                        xmls.Serialize(stream, pageSettings);

                        //stream.Seek(0, SeekOrigin.Begin);//回到开头。

                    }
                    //如下是反序列化
                    using (Stream stream = new FileStream(Application.StartupPath + "\\tempPageSettings", FileMode.Open, FileAccess.Read, FileShare.Read))
                    {

                        XmlSerializer xmls = new XmlSerializer(typeof(ClsPageSettings));
                        //如下是反序列化
                        BarcodePageSettings = xmls.Deserialize(stream) as ClsPageSettings;

                    }
                }
            #endregion

                myInit();

            }
            catch (Exception exception)
            {
                //ClsErrorFile.WriteLine("不成功,原因是", exception);
                //MessageBox.Show("保存不成功,原因是" + exception.Message);

                if (exception.InnerException.Message != null)
                {
                    //ClsErrorFile.WriteLine("xml不成功" + exception.InnerException.Message);
                    //MessageBox.Show(exception.InnerException.Message);
                }
            }
            finally
            {

            }
            #endregion
        }