private static bool EvaluatePropertyRestriction(Restriction.PropertyRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidatePropertyRestriction(restriction); PropTag propTag = restriction.PropTag; if (restriction.MultiValued) { propTag = RuleUtil.GetMultiValuePropTag(propTag); } context.TraceFunction <PropTag, Restriction.RelOp, object>("PropertyRestriction [{0}] {1} [{2}]", propTag, restriction.Op, restriction.PropValue.Value); object obj = context[propTag]; bool flag; if (obj == null) { flag = false; } else if (restriction.MultiValued) { flag = RestrictionEvaluator.CompareMultiValueWithValue(context, RuleUtil.GetSingleValuePropTag(restriction.PropTag), restriction.Op, obj, restriction.PropValue.Value); } else if (RuleUtil.IsMultiValueTag(restriction.PropValue.PropTag)) { flag = RestrictionEvaluator.CompareValueWithMultiValue(context, restriction.PropTag, restriction.Op, obj, restriction.PropValue.Value); } else { flag = context.CompareSingleValue(restriction.PropTag, restriction.Op, obj, restriction.PropValue.Value); } context.TraceFunction <bool, object>("PropertyRestriction evaluated to {0} with property value [{1}]", flag, obj); return(flag); }
private static bool EvaluateComparePropertyRestriction(Restriction.ComparePropertyRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidateComparePropertyRestriction(restriction); object obj = context[restriction.TagLeft]; object obj2 = context[restriction.TagRight]; context.TraceFunction <PropTag, Restriction.RelOp, PropTag>("ComparePropertyRestriction [{0}] {1} [{2}]", restriction.TagLeft, restriction.Op, restriction.TagRight); bool flag = false; if (obj != null && obj2 != null) { flag = context.CompareSingleValue(restriction.TagLeft, restriction.Op, obj, obj2); } context.TraceFunction <object, Restriction.RelOp, object, bool>("[{0}] {1} [{2}] evaluated to {3}", obj, restriction.Op, obj2, flag); return(flag); }
private static bool CompareValueWithMultiValue(IRuleEvaluationContext context, PropTag tag, Restriction.RelOp op, object messageValue, object ruleValueObject) { Array array = (Array)ruleValueObject; bool flag = false; foreach (object y in array) { flag = context.CompareSingleValue(tag, Restriction.RelOp.Equal, messageValue, y); if (flag) { break; } } if (op == Restriction.RelOp.NotEqual) { flag = !flag; } return(flag); }
private static bool CompareMultiValueWithValue(IRuleEvaluationContext context, PropTag tag, Restriction.RelOp op, object messageValueObject, object ruleValue) { Array array = (Array)messageValueObject; bool flag = false; foreach (object x in array) { flag = context.CompareSingleValue(tag, op, x, ruleValue); if (flag) { if (op != Restriction.RelOp.NotEqual) { break; } } else if (op == Restriction.RelOp.NotEqual) { break; } } return(flag); }