public static bool ParseAndEvaluate(string condition, IExpressionContext 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); } }
public override bool BoolEvaluate(IExpressionContext 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 override bool CanEvaluateToBool(IExpressionContext context) { return(expression.CanEvaluateToBool(context)); }
public override bool CanEvaluateToBool(IExpressionContext context) { // Short-circuiting, check only left expr, right // would be required only if left == true return(left.CanEvaluateToBool(context)); }