[]
        
(Showing Draft Content)

Understand Range Property

The Range property is a collection of RulesEngineRange objects, and each object defines a subset of items, a subset of field or both. This allows the Rules Manager to have control over when and where a rule should be evaluated.

The Rule’s Ranges

Every rule has a scope determined by the Range property. This is a collection of RulesEngineRange which can be defined by a collection of fields and/or a range of items.

Range to string conversion

For xaml and serialization purposes, there is a type-converter from string, with some specific syntax.

  • The ranges can be separated using “;”
  • Every range can have up to 3 parts separated by “:”
  • If a range has only one part, that part is about the fields.
  • if a range has two parts, that parts are the first and last indexes.
  • If a range has three parts, the first and second are the indexes and the third is a list of fields.
  • The list of fields can be separated using “,”.
  • The field names are enclosed in square brackets “[field]“

For instance,

  • “[FirstName]“, the scope is the field “FirstName”.
  • “5:10“ the scope is from item 5 to item 10.
  • “4:8:[FirstName],[LastName]“ the scope are the fields FirstName and LastName but only from items 4 to 8.
  • “3:6:[FirstName];8:12:[LastName]“ the scope is from item 3 to 6 on field FirstName, and from 8 to 12 on field LastName.

Parse from a String

The Range property of a rule can be defined using the static method (Parse or TryParse).

rule.Ranges = RulesEngineRangeCollection.Parse(string stringValue)
// there is also constructor
rule.Ranges = new RulesEngineRangeCollection(stringValue)

Parse or TryParse methods converts a string representation of a Range into a RulesEngineRangeCollection. The string should follow the syntax rules described above (Example, "3:6:[FirstName];8:12:[LastName]").

// Parse a range string into Ranges collection
rule.ranges = RulesEngineRangeCollection.Parse("3:6:[FirstName];8:12:[LastName]")

Create a Range Programmatically

Build the Range collection manually using code

rule.Ranges = new RulesEngineRangeCollection()
{
    new RulesEngineRange(fieldName),
    new RulesEngineRange(firstItem, lastItem, fieldName2)
    // ...
};