Ejemplo n.º 1
0
        private static Object IntenalEval(ExpressionNode node, IDataResolver dataResolver)
        {
            switch (node.ActionType)
            {
                case ActionTypes.Function:
                    return FunctionEvaluator.Eval(node, dataResolver);
                case ActionTypes.Operator:
                    return OperatorEvaluator.Eval(node, dataResolver);
            }

            switch (node.ValueType)
            {
                case ValueTypes.Variable:
                    {
                        if (_ordinalComparer.Equals(node.Action, "e"))
                            return Math.E;

                        if (_ordinalComparer.Equals(node.Action, "pi"))
                            return Math.PI;

                        if (_ordinalComparer.Equals(node.Action, "true"))
                            return true;

                        if (_ordinalComparer.Equals(node.Action, "false"))
                            return false;

                        if (_ordinalComparer.Equals(node.Action, "null"))
                            return null;

                        return dataResolver.GetValue(node.Action);
                    }
            }

            return node.Value;
        }
Ejemplo n.º 2
0
        public Object Eval(ExpressionNode node)
        {
            if (node == null)
            {
                return(null);
            }

            switch (node.ActionType)
            {
            case ActionTypes.Function:
                return(FunctionEvaluator.Eval(node, this));

            case ActionTypes.Operator:
                return(OperatorEvaluator.Eval(node, this));
            }

            switch (node.ValueType)
            {
            case ValueTypes.Variable:
            {
                if (String.Equals(node.Action, "e", StringComparison.OrdinalIgnoreCase))
                {
                    return(Math.E);
                }

                if (String.Equals(node.Action, "pi", StringComparison.OrdinalIgnoreCase))
                {
                    return(Math.PI);
                }

                if (String.Equals(node.Action, "true", StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }

                if (String.Equals(node.Action, "false", StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }

                return(variableResolver(node.Action));
            }
            }

            return(node.Value);
        }