Exemplo n.º 1
0
        private bool EvalCondition(Expression expr, TemplateContext context)
        {
            object val = expr.Eval(context);

            if (val is Boolean)
            {
                return((Boolean)val);
            }
            else if (val is Int32)
            {
                return(((Int32)val) != 0);
            }
            else if (val is Decimal)
            {
                return(((Decimal)val) != 0);
            }
            else if (val != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public override object Eval(TemplateContext context)
        {
            // evaluate right side
            object val = rhs.Eval(context);

            if (op == TokenType.Minus && val is Decimal)
            {
                return(-(Decimal)val);
            }
            else if (op == TokenType.Minus && val is Int32)
            {
                return(-(Int32)val);
            }
            else if (op == TokenType.Not && val is Boolean)
            {
                return(!(Boolean)val);
            }

            throw new ParserException("Unary operator can be applied to integer, decimal and boolean expressions.", Line, Column);
        }
Exemplo n.º 3
0
 private bool EvalCondition(Expression expr, TemplateContext context)
 {
     object val = expr.Eval(context);
     if (val is Boolean)
         return (Boolean)val;
     else if (val is Int32)
         return ((Int32)val) != 0;
     else if (val is Decimal)
         return ((Decimal)val) != 0;
     else if (val != null)
         return true;
     else
         return false;
 }