Evaluation Type Rules

A rule of evaluation type always boils down to one simple answer: True or False. 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.

The structure of an evaluation type rule is shown below (with some formatting):

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

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

For Code Effects 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.

Code Effects component 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>(ruleXml).Evaluate(sourceInstance);

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

Code Effects component also supports situations where the source objects are declared at run-time and their exact types are not known at design-time. See topics for Evaluator and DynamicEvaluator 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, as long as that code references the CodeEffects.Rule.dll assembly.

Comments: 0
Name (optional):
Comment (URLs are allowed and must start with http:// or https://; all tags will be encoded):
Remaining character count: