示例#1
0
        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));
        }
示例#2
0
文件: Test.cs 项目: havocbcn/LIS
        public Operation AddOperation(string name)
        {
            var operation = operationFactory.CreateOperation(name);

            operations.Add(operation);
            return(operation);
        }
示例#3
0
 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);
        }
示例#5
0
        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());
        }