zoukankan      html  css  js  c++  java
  • 深copy

    更好的对一个对象进行复制

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using ChartUtil;
     6 using System.Windows.Forms;
     7 using System.IO;
     8 using System.Runtime.Serialization;
     9 using System.Runtime.Serialization.Formatters.Binary;
    10 //using System.Runtime.Serialization.Formatters.Soap;
    11 
    12 namespace NetAnalysis.Common
    13 {
    14     public static class DrawChartExtensionMethodClass
    15     {
    16 
    17 
    18         #region 单击事件
    19         public static void ChartMouseRigthClick(this DrawChart dict)
    20         {
    21 
    22             dict.ChartMouseClick += delegate
    23             {
    24 
    25                 MessageBox.Show("kkk");
    26             };
    27         }
    28 
    29 
    30 
    31 
    32         #endregion
    33     }
    34 
    35     [Serializable]
    36     public class TimeRegion : ICloneable
    37     {
    38 
    39         public List<List<DateTime>> timeregion = new List<List<DateTime>>();
    40 
    41 
    42         #region ICloneable 成员
    43 
    44         public object Clone()
    45         {
    46         //  return this.MemberwiseClone();
    47             return new TimeRegion() as TimeRegion ;
    48         }
    49 
    50         #endregion
    51 
    52         public TimeRegion DeepClone()
    53         {
    54             using (Stream objectStream = new MemoryStream())
    55             {
    56                 IFormatter formatter = new BinaryFormatter();
    57                 //IFormatter formatter = new SoapFormatter();
    58                 formatter.Serialize(objectStream, this);
    59                 objectStream.Seek(0, SeekOrigin.Begin);
    60                 return formatter.Deserialize(objectStream) as TimeRegion;
    61             }
    62 
    63             ////这个版本有问题
    64             //TimeRegion rtd = new TimeRegion();
    65             //rtd.timeregion = this.timeregion;
    66 
    67             //return rtd;
    68         }
    69 
    70         public TimeRegion ShallowClone()
    71         {
    72             return Clone() as TimeRegion;
    73         }
    74 
    75 
    76 
    77     }
    78 }
  • 相关阅读:
    解决命令行乱码问题(中文乱码)
    Outlook 修改归档文件顶层目录名
    (职员)2015-11-11 星期三 日志
    职员)2015-11-10 星期二 日志
    职员)2015-11-09 星期一 日志
    (职员)2015-11-05 星期四 日志
    (职员)2015-11-04 星期三 日志
    (职员)2015-11-03 星期二 日志
    (职员)2015-11-02 星期一 日志
    (职员)2015-10-31 星期六 周志
  • 原文地址:https://www.cnblogs.com/ants_double/p/5365007.html
Copyright © 2011-2022 走看看