void Apply(object undoObject, object toApplyTo, ElementSave parent) { if (toApplyTo != null && toApplyTo is StateSave && undoObject is StateSave) { StateSave undoStateSave = undoObject as StateSave; StateSave toApplyToStateSave = toApplyTo as StateSave; toApplyToStateSave.SetFrom(undoStateSave); } else if (toApplyTo != null && toApplyTo is List <InstanceSave> && undoObject is List <InstanceSave> ) { List <InstanceSave> listToApplyTo = (List <InstanceSave>)toApplyTo; List <InstanceSave> undoList = (List <InstanceSave>)undoObject; listToApplyTo.Clear(); foreach (var instance in undoList) { instance.ParentContainer = parent; listToApplyTo.Add(instance); } } }