Esempio n. 1
0
        public static bool ParseAndEvaluate(string condition, Project context)
        {
            if (String.IsNullOrEmpty(condition))
            {
                return(true);
            }

            try {
                ConditionExpression ce = ParseCondition(condition);

                if (!ce.CanEvaluateToBool(context))
                {
                    throw new InvalidProjectFileException(String.Format("Can not evaluate \"{0}\" to bool.", condition));
                }

                return(ce.BoolEvaluate(context));
            } catch (ExpressionParseException epe) {
                throw new InvalidProjectFileException(
                          String.Format("Unable to parse condition \"{0}\" : {1}", condition, epe.Message),
                          epe);
            } catch (ExpressionEvaluationException epe) {
                throw new InvalidProjectFileException(
                          String.Format("Unable to evaluate condition \"{0}\" : {1}", condition, epe.Message),
                          epe);
            }
        }
Esempio n. 2
0
        public override bool BoolEvaluate(Project context)
        {
            if (left.CanEvaluateToNumber(context) && right.CanEvaluateToNumber(context))
            {
                float l, r;

                l = left.NumberEvaluate(context);
                r = right.NumberEvaluate(context);

                return(NumberCompare(l, r, op));
            }
            else if (left.CanEvaluateToBool(context) && right.CanEvaluateToBool(context))
            {
                bool l, r;

                l = left.BoolEvaluate(context);
                r = right.BoolEvaluate(context);

                return(BoolCompare(l, r, op));
            }
            else
            {
                string l, r;

                l = left.StringEvaluate(context);
                r = right.StringEvaluate(context);

                return(StringCompare(l, r, op));
            }
        }
        public static bool ParseAndEvaluate(string condition, IExpressionContext context)
        {
            if (String.IsNullOrEmpty(condition))
            {
                return(true);
            }

            ConditionExpression ce = ParseCondition(condition);

            if (!ce.CanEvaluateToBool(context))
            {
                throw new Exception(String.Format("Can not evaluate \"{0}\" to bool.", condition));
            }

            return(ce.BoolEvaluate(context));
        }
Esempio n. 4
0
 public override bool CanEvaluateToBool(Project context)
 {
     // Short-circuiting, check only left expr, right
     // would be required only if left == true
     return(left.CanEvaluateToBool(context));
 }
Esempio n. 5
0
 public override bool CanEvaluateToBool(IExpressionContext context)
 {
     return(left.CanEvaluateToBool(context) && right.CanEvaluateToBool(context));
 }
Esempio n. 6
0
 public override bool CanEvaluateToBool(Project context)
 {
     return(left.CanEvaluateToBool(context) && right.CanEvaluateToBool(context));
 }
Esempio n. 7
0
 public override bool CanEvaluateToBool(Project context)
 {
     return(expression.CanEvaluateToBool(context));
 }