Esempio n. 1
0
        /// <summary>
        /// Evaluates the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        public decimal Evaluate(IToken[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            else if (args.Length != this._argumentCount)
            {
                throw new ArgumentException(string.Format("The number of arguments should equal {0}.", this._argumentCount), "args");
            }

            decimal[] numbers = args.ConvertToDecimalArray();

            decimal result = 0.0M;
            switch(this._operatorType)
            {
                case OperatorType.Add:
                    result = Add(numbers);
                    break;

                case OperatorType.Divide:
                    result = Divide(numbers);
                    break;

                case OperatorType.Modulo:
                    result = Modulo(numbers);
                    break;

                case OperatorType.Multiply:
                    result = Multiply(numbers);
                    break;

                case OperatorType.RaiseTo:
                    result = RaiseTo(numbers);
                    break;

                case OperatorType.Subtract:
                    result = Subtract(numbers);
                    break;

                case OperatorType.UnaryMinus:
                    result = UnaryMinus(numbers);
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Unsupported operator type '{0}'.", this._operatorType));
            }

            return result;
        }