Navigation

Categories
Show Navigation Next Topic  »

Evaluation Type Rules

The entire purpose of a rule of evaluation type is to return a System.Boolean value. It cannot (and 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 initiated the rule evaluation is only interested in knowing if the source object "passes the test". That external code handles further processing of the source object after the result of the rule evaluation is received and inspected.

The evaluation type rules still employ parentheses to prioritize evaluation of condition groups, and other great Code Effects features such as in-rule methods or 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, allowing you to reuse common business logic in other rules of any type. This rule type can also be used as data filters for creating amazing search functionality, super grids, and so on.

The structure of an evaluation type rule is shown below (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 100
) 

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

For the Rule Editor to be able to create rules of evaluation type, the source object or any of its reference type members must declare at least one public property or field of value type (except for System.Guid and nullable enum.), or it must declare or reference at least one public method that returns a value type. Those members become rule fields and in-rule methods. Members decorated with ExcludeFromEvaluationAttribute are ignored by Code Effects.

The Rule Editor provides several options you can use to change the way it "scans" source objects for fields and in-rule methods. Make sure to read the source object topic for complete details on the subject.

If the type of source object is known at run-time, the rule can be evaluated by calling the Evaluate method of Evaluator<TSource> class:

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

A value of True in the success variable indicates that the rule's evaluation was successful.

Code Effects rules engine also supports situations where the exact type of the source object is either not known, or not available at design-time. See the topic for source object types and Evaluator classes for details.

In Code Effects, rules can be created using the Rule Editor or Rule XML schema, but the evaluation of rules does not need to be part of the same web application that created them. You can evaluate rules in any .NET code.


Post your questions on Stackoverflow and become a part of our growing community

Comments: 0