日期:2014-05-18  浏览次数:21111 次

C# Dictionary<String,类>深拷贝问题 请大牛帮忙
private Dictionary<String, ReportTypeElement> ReportTypeIndexDocList { get; set; }


  public class ReportTypeElement
  {
  private List<ReportTypeInfo> ReportTypeInfoList { get; set; }

  /// <summary>
  /// 0: Delete; 1: normal; 2: new; 3: modify
  /// </summary>
  private int Status { get; set; }
  }

 public class ReportTypeInfo
  {
  public String Name { get; set; }

  public DateTimeList dateTimeList { get; set; }
  /// <summary>
  /// 0: Delete; 1: normal; 2: new; 3: modify
  /// </summary>
  private int Status { get; set; }
  }
是一层层嵌套的 请问 如何进行深拷贝 我都困扰了 两天了 谢谢

------解决方案--------------------
C# code
/// <summary>
        /// 得到一个对象的克隆
        /// </summary>
        public static object Clone(object obj)
        {
            MemoryStream memoryStream = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(memoryStream, obj);
            memoryStream.Position = 0;
            return formatter.Deserialize(memoryStream);
        }

------解决方案--------------------
C# code/// <summary>
/// 得到一个对象的克隆
/// </summary>
public static object Clone(object obj)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, obj);
memoryStream.Position = 0;
return formatter.Deserialize(memoryStream);
}


object obj = Clone(ReportTypeIndexDocList );
将obj 转化成Dictionary<String, ReportTypeElement> 类型即可
--reply by CSDN Study V1.0.0.3 (starts_2000)