Evaluation Type Rules

A rule of evaluation type always answers only one simple question: True or False. It cannot (or should not) invoke any actions, it does not have flow elements else if or else and uses only two clauses - and and or. This type of rule assumes that the external code that initiates the rule evaluation is only interested to know if the source object "passes the test". That external code handles further processing of source object after the result of rule evaluation is received and inspected.

The evaluation type rules still employ parentheses to prioritize evaluation of condition groups, though. Other Web Rule great features such as in-rule methods or source object's attribute classes are available for this type as well.

Evaluation type is the only rule type that can be reused in any other rule as a field.

The structure of evaluation type rule looks like this (with some formatting):

Check if
(
	A is greater than B
	or
	C contains "abc"
)
and
(
	D is not equal to { (A x B) - (E x F) } 
	or
	E is less or equal to F
) 

The A, B, C, D, E and F are known as rule fields. Fields can be value type properties of a source object, or in-rule methods, or other rules of evaluation type.

For Web Rule to be able to create rules of evaluation type, source object or any of its reference type members must have at least one public property or field of value type, except for System.Guid and nullable enum. Those members will become rule fields. Members decorated with ExcludeFromEvaluationAttribute will be ignored.

Web Rule provides many options you can use to change the way it scans source object for fields. Make sure to read the source object topic for complete details on the subject.

The rule can be evaluated by calling the Evaluate method of Evaluator class:

using CodeEffects.Rule.Core;
...
bool success = new Evaluator<SourceType>(ruleXml).Evaluate(sourceInstance);

Value of True of the success variable indicates that the rule's evaluation was successful. The Result also contains list of all fields that have failed evaluation during the evaluation of the entire rule.

Although rules can only be created using the web UI outputted by Asp.RuleEditor or Mvc.RuleEditor classes, the Evaluator class does not need to be part of the same web application that created the rules in order to evaluate them. You can evaluate rules in any .Net code, as long as it references CodeEffects.Rule.dll assembly.

Code Effects Software ©  · Web Scheduler · CodeEffects.com
Current version 2.0.1.4 · Built on March 27, 2012
Terms and Conditions · Privacy Policy