Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string GetParameterValue()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(FirstOperand.GetParameterValue());
            switch (Operation)
            {
            case MathOperation.Division:
                sb.Append("/");
                break;

            case MathOperation.Minus:
                sb.Append("-");
                break;

            case MathOperation.Multiplication:
                sb.Append("*");
                break;

            case MathOperation.Plus:
                sb.Append("+");
                break;
            }
            sb.Append(SecondOperand.GetParameterValue());

            return(sb.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Gets the parameter value.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <returns>
        /// Parameter value.
        /// </returns>
        public override string GetParameterValue(RootModel rootModel, ActionExecutionContext context)
        {
            Assert.ArgumentNotNull(rootModel, "rootModel");
            Assert.ArgumentNotNull(context, "context");

            var leftVal  = FirstOperand.GetParameterValue(rootModel, context);
            var rightVal = SecondOperand.GetParameterValue(rootModel, context);

            double leftValueNumeric;
            double rightValueNumertic;

            bool isLeftValueNumeric  = double.TryParse(leftVal, NumberStyles.Any, CultureInfo.InvariantCulture, out leftValueNumeric);
            bool isRightValueNumeric = double.TryParse(rightVal, NumberStyles.Any, CultureInfo.InvariantCulture, out rightValueNumertic);

            if (isRightValueNumeric && isLeftValueNumeric)
            {
                switch (Operation)
                {
                case MathOperation.Plus:
                    return((leftValueNumeric + rightValueNumertic).ToString(CultureInfo.InvariantCulture));

                case MathOperation.Minus:
                    return((leftValueNumeric - rightValueNumertic).ToString(CultureInfo.InvariantCulture));

                case MathOperation.Multiplication:
                    return((leftValueNumeric * rightValueNumertic).ToString(CultureInfo.InvariantCulture));

                case MathOperation.Division:
                    return(rightValueNumertic == 0
                                   ? string.Empty
                                   : (leftValueNumeric / rightValueNumertic).ToString(CultureInfo.InvariantCulture));
                }
            }
            else
            {
                if (Operation == MathOperation.Plus)
                {
                    return(leftVal + rightVal);
                }
            }

            return(string.Empty);
        }