private void SetupPriority(IPriorityService piorityService, IOperationFactory operationFactory) { piorityService.AddToPiority(1, operationFactory.CreateOperation(OperationEnum.Multiplication)); piorityService.AddToPiority(1, operationFactory.CreateOperation(OperationEnum.Division)); piorityService.AddToPiority(2, operationFactory.CreateOperation(OperationEnum.Add)); piorityService.AddToPiority(2, operationFactory.CreateOperation(OperationEnum.Subtract)); }
public Operation AddOperation(string name) { var operation = operationFactory.CreateOperation(name); operations.Add(operation); return(operation); }
public static IEnumerable <Operation> GetOperations(this IEnumerable <OperationEvent> operationEvents, IOperationFactory <OperationEvent> factory) { foreach (var operationEvent in operationEvents) { yield return(factory.CreateOperation(operationEvent)); } }
public IOperation GetOperation(OperationTypes operationType) { if (!Enum.IsDefined(typeof(OperationTypes), operationType)) { throw new InvalidEnumArgumentException(nameof(operationType)); } if (_operations.ContainsKey(operationType)) { return(_operations[operationType]); } var operation = _operationFactory.CreateOperation(operationType); _operations.Add(operationType, operation); return(operation); }
public IOperand EvaluateExpression(IEnumerable <string> tokens) { this.machineStack.Clear(); if (tokens == null) { throw new ArgumentNullException(); } foreach (var token in tokens) { if (operationTable.Contains(token)) { var operation = operationFactory.CreateOperation(token); EvaluateOperation(operation); continue; } try { var operand = IntType.Parse(token); this.machineStack.Push(operand); } catch (ArgumentException) { throw new InvalidMathematicalExpressionException( string.Format(ErrorMessages.UnrecognizedElement, token)); } } if (this.machineStack.Count != 1) { throw new InvalidMathematicalExpressionException(); } return(this.machineStack.Pop()); }