public void Calculate(IDoubleNumericalOperation numericalOperationRequest) { if (numericalOperationRequest.OperationType == _operationType) { var result = numericalOperationRequest.First * numericalOperationRequest.Second; Console.WriteLine($"Multiplying two numbers {numericalOperationRequest.First} and {numericalOperationRequest.Second}. Result is {result}."); } else { _nextCalculatorChain.Calculate(numericalOperationRequest); } }
public void Calculate(IDoubleNumericalOperation numericalOperationRequest) { if (numericalOperationRequest.OperationType == _operationType) { if (numericalOperationRequest.Second == 0.0) { throw new DivideByZeroException(); } var result = numericalOperationRequest.First / numericalOperationRequest.Second; Console.WriteLine($"Dividing two numbers {numericalOperationRequest.First} and {numericalOperationRequest.Second}. Result is {result}."); } else { _nextCalculatorChain.Calculate(numericalOperationRequest); } }
public void Calculate(IDoubleNumericalOperation numericalOperationRequest) { // when the chain could not handle the request, we end up here throw new InvalidEnumArgumentException($"Chain was unable to handle {numericalOperationRequest.OperationType}"); }