示例#1
0
        /// <summary>
        /// Evalaute this node and return result.
        /// </summary>
        /// <param name="thisObject">Reference to object that is exposed as 'this'.</param>
        /// <returns>Result value and type of that result.</returns>
        public override EvalResult Evaluate(object thisObject)
        {
            // Get the result from evaluating both children
            EvalResult left  = this[0].Evaluate(thisObject);
            EvalResult right = this[1].Evaluate(thisObject);

            // Both sides must be converted to doubles
            if (!ImplicitConverter.CanConvertToDouble(left.Value, _language))
            {
                throw new ApplicationException("Cannot convert '" + left.Type.ToString() + "' type to 'Double' for left side of exponent '^' operation.");
            }

            if (!ImplicitConverter.CanConvertToDouble(right.Value, _language))
            {
                throw new ApplicationException("Cannot convert '" + left.Type.ToString() + "' type to 'Double' for right side of exponent '^' operation.");
            }

            double leftDouble  = ImplicitConverter.ConvertToDouble(left.Value, _language);
            double rightDouble = ImplicitConverter.ConvertToDouble(right.Value, _language);

            return(new EvalResult(TypeCode.Double, Math.Pow(leftDouble, rightDouble)));
        }