/// <summary> /// Automatically pushes given <see cref="IUndoRedoCommand"/> command on the Undo stack. /// </summary> public void Push(IUndoRedoCommand cmd) { // assertion #if DEBUG if (cmd == null) { throw new ArgumentNullException("cmd", "cmd parameter cannot be null."); } #endif if (cmd is EditCommand <IModel> ) { // check if rely on anything else (only Edit and Remove) for (int i = 0; i < _undoRedoStack.Count; i++) { IUndoRedoCommand c = _undoRedoStack[i]; if (cmd.GetType().GetGenericTypeDefinition() == typeof(AddCommand <>) || cmd.GetType().GetGenericTypeDefinition() == typeof(RemoveCommand <>)) { if (cmd.TargetObject == c.TargetObject) { (cmd as EditCommand <IModel>).RelyOn = c; } } // this would not work //if (cmd is AddCommand<IModel>) } } _undoRedoStack.Insert(_pointer++, cmd); _onUndoAction?.Invoke(); _onRedoAction?.Invoke(); }
public static string ToTypeName(IUndoRedoCommand command) { return(NamesByType[command.GetType()]); }