コード例 #1
0
        public object DeepClone(object source, ICloningFactory factory)
        {
            this.factory = factory;
            var clonedObj = memberwiseClone.Invoke(source, null);

            factory.RegisterClonedObject(source, clonedObj);
            ClonePublicFieldsProperties(source, clonedObj);
            return(clonedObj);
        }
コード例 #2
0
ファイル: ListCloner.cs プロジェクト: swoo888/DeepClone
        public object DeepClone(object source, ICloningFactory factory)
        {
            var sourceList = source as IList;
            var clonedList = Activator.CreateInstance(source.GetType()) as IList;

            factory.RegisterClonedObject(source, clonedList);
            for (int i = 0; i < sourceList.Count; i++)
            {
                var sourceValue = sourceList[i];
                clonedList.Insert(i, factory.CloneObject(sourceList[i], CloningMode.Deep));
            }
            return(clonedList);
        }
コード例 #3
0
ファイル: ArrayCloner.cs プロジェクト: swoo888/DeepClone
        public object DeepClone(object source, ICloningFactory factory)
        {
            var sourceArray = source as Array;
            var clonedArray = (source as Array).Clone() as Array;

            factory.RegisterClonedObject(source, clonedArray);
            for (int i = 0; i < sourceArray.Length; i++)
            {
                var sourceValue = sourceArray.GetValue(i);
                clonedArray.SetValue(factory.CloneObject(sourceArray.GetValue(i), CloningMode.Deep), i);
            }
            return(clonedArray);
        }