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); }
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); }
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); }