static void Main(string[] args) { var invoker = new Invoker(); var calculator = new Calculator(); var command1 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Add, 10); var command2 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Multiply, 5); var command3 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Subtract, 5); var command4 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Divide, 5); invoker.Command = command1; invoker.Invoke(); invoker.Command = command2; invoker.Invoke(); invoker.Command = command3; invoker.Invoke(); invoker.Undo(); invoker.Command = command4; invoker.Invoke(); Console.WriteLine($"Result is : {calculator.Value}"); }
public void Compute(char @operator, int operand) { Command command = new CalculatorCommand(this.calculator, @operator, operand); command.Execute(); this.commands.Add(command); this.current++; }
public void Compute(char @operator, int operand) { var command = new CalculatorCommand(_calculator, @operator, operand); command.Execute(); _commands.Add(command); _current++; }
public void Compute(char @operator, int operand) { // Create command operation and execute it Command command = new CalculatorCommand(_calculator, @operator, operand); command.Execute(); _commands.Add(command); _commandsCount++; }
public void Compute(char @operator, int operand) { // create the command and execute it var command = new CalculatorCommand(@operator, operand, _calculator); command.Execute(); // Add operation to the cancel list _commandHistory.Add(command); _current++; }
public void Compute(char @operator, int operand) { // Create command opearation and execue it Command command = new CalculatorCommand(_calculator, @operator, operand); command.Execute(); //Add command to undo list _commands.Add(command); _current++; }
public void Compute(char @operator, int operand) { // Create command operation and execute it Command command = new CalculatorCommand( _calculator, @operator, operand); command.Execute(); // Add command to undo list _commands.Add(command); _current++; }
/// <summary> /// The compute. /// </summary> /// <param name="operator"> /// The operator. /// </param> /// <param name="operand"> /// The operand. /// </param> public void Compute(char @operator, int operand) { // Create command operation and execute it AnAbstractCommand command = new CalculatorCommand( this.Calculator, @operator, operand); command.Execute(); // Add command to undo list this.Commands.Add(command); this.Current++; }
public void Compute(char @operator, int operand) { Command command = new CalculatorCommand( _calculator, @operator, operand); command.Execute(); if (_current < _commands.Count) { _commands.RemoveRange(_current, _commands.Count - _current); } _commands.Add(command); _current++; }
public void Compute(char @operator, int operand) { // Create command operation and execute it Command command = new CalculatorCommand( _calculator, @operator, operand); command.Execute(); //fix the redo list bug if (_commands.Count > _current) { _commands.RemoveRange(_current, _commands.Count - _current); } // Add command to undo list _commands.Add(command); _current++; }
public void Compute(char @operator, int operand) { // Создаем команду операции и выполняем её Command command = new CalculatorCommand( _calculator, @operator, operand); command.Execute(); if (_current < _commands.Count) { // если "внутри undo" мы запускаем новую операцию, // надо обрубать список команд, следующих после текущей, // иначе undo/redo будут некорректны _commands.RemoveRange(_current, _commands.Count - _current); } // Добавляем операцию к списку отмены _commands.Add(command); _current++; }