RuleQuery Class

Assembly: CodeEffects.Rule.Common.dll
Namespace: CodeEffects.Rule.Common.Models

Summary

Describes which rules of a Rule Repository to load for evaluation. You build a query with one of the static methods, optionally narrow it with the instance methods, and pass it to Context.GetRules(..) of the Rule Repository library or to AuditRecorder.GetRules(..) of the Audit library. Both libraries take the same type.

Syntax

public sealed class RuleQuery

Remarks

A query always loads the live version of each rule it finds, together with the live versions of every rule those rules call or execute. There is no way to ask for a version by number: a version your application should evaluate is a version someone made live.

You cannot create a RuleQuery with new. Start with ByIds(..), ByNames(..) or BySource(..), then chain InSource(..) and OfType(..) to narrow it. Every instance method returns the same query, so the calls chain.

The query itself reads nothing. It is evaluated by the library you pass it to. See Rule Storage in Rule Repository for how an application loads rules.

Static Methods

  • ByIds(..)

    Returns: CodeEffects.Rule.Common.Models.RuleQuery - A query for the rules with the specified IDs.

    public static RuleQuery ByIds(params Guid[] ids)

    Creates a query for the rules with these IDs: the IDs that the Rule Editor gives rules and that their Rule XML carries. Duplicate IDs are ignored.

    Parameters

    • ids (System.Guid[]) - The IDs of the rules to load. Cannot be null or empty.

    Exceptions

    • System.ArgumentException - No ID was passed.

    Example

      var query = RuleQuery.ByIds(rule1Id, rule2Id);
    
  • ByNames(..)

    Returns: CodeEffects.Rule.Common.Models.RuleQuery - A query for the rules with the specified names.

    public static RuleQuery ByNames(params string[] names)

    Creates a query for the rules with these names. Names are compared exactly, including case. When the same name is used by rules of different source objects, narrow the query with InSource(..).

    Parameters

    • names (System.String[]) - The names of the rules to load. Cannot be null or empty, and no name can be empty or white space.

    Exceptions

    • System.ArgumentException - No name was passed, or one of the names is empty.

    Example

      var query = RuleQuery.ByNames("Approve large orders").InSource("MyApp.Orders.Order");
    
  • BySource(..)

    Returns: CodeEffects.Rule.Common.Models.RuleQuery - A query for every rule of the specified source object.

    public static RuleQuery BySource(string alias)
    public static RuleQuery BySource(int sourceId)

    Creates a query for every rule of a source object that has a live version. The source object is named by its alias, which is its class name unless you gave it another, or by its ID in the repository.

    Parameters

    • alias (System.String) - The alias of the source object. Cannot be null, empty or white space.
    • sourceId (System.Int32) - The ID of the source object in the repository.

    Exceptions

    • System.ArgumentException - The alias is null, empty or white space.

    Example

      var query = RuleQuery.BySource("MyApp.Orders.Order");
    

Methods

  • InSource(..)

    Returns: CodeEffects.Rule.Common.Models.RuleQuery - This query.

    public RuleQuery InSource(string alias)
    public RuleQuery InSource(int sourceId)

    Narrows the query to the rules of one source object, named by its alias or by its ID. Use it with ByIds(..) or ByNames(..).

    Parameters

    • alias (System.String) - The alias of the source object. Cannot be null, empty or white space.
    • sourceId (System.Int32) - The ID of the source object in the repository.

    Exceptions

    • System.ArgumentException - The alias is null, empty or white space.
  • OfType(..)

    Returns: CodeEffects.Rule.Common.Models.RuleQuery - This query.

    public RuleQuery OfType(bool evaluationType)

    Narrows the query to rules of one type.

    Parameters

    Example

      // Only the evaluation type rules of the source object
      var query = RuleQuery.BySource("MyApp.Orders.Order").OfType(true);
    

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×