一个对象中有若干Dictionary,除了序列化反序列化此对象,有没有其它方法可以使包含Dictionary的对象深度拷贝,或者实现Dictionary的clone?因为查了下网上说序列化反序列化好像消耗比较大,而我的对象正好是属于那种属性比较多,且不停的使用的,要经常深度拷贝

解决方案 »

  1.   

    比如这样一个字典key类型为int, value类型为一个自定义的类,此类我已经实现clone,此时含此字典的父类该如何写深拷贝呢?
      

  2.   

    Dictionary<int, objcet> dicdest = new Dictionary<int, object>();
    foreach(int index in dic.Keys)
    {
    object obj = dic[index].Clone();
    dicdest.Add(index, obj);
    }
      

  3.   

      IDictionary<string, object> attributes = new Dictionary<string, object>();
    IDictionary<string, object> attributes1 = new Dictionary<string, object>();
                if (attributes != null)
                    foreach (KeyValuePair<string, object> kvp in attributes)
                    {
                        attributesSelectItems0.Add(kvp);
                    }