Rule based filtering using expression trees.
Go to file
Sean McArde cdc819d2f5 Updated readme and bumped version. 2024-04-23 16:11:08 -07:00
.github/workflows Create dotnet-library.yml 2023-07-24 14:23:56 -07:00
.idea Adding jetbrains specific files. 2023-03-13 18:10:31 -07:00
McRule Updated readme and bumped version. 2024-04-23 16:11:08 -07:00
McRule.EF TEST BROKEN - working on EF string comparisons. 2023-09-02 11:30:15 -07:00
McRule.Tests Added test for case insensitive comparison. 2024-04-23 16:07:37 -07:00
RulerDev Merge branch 'dev' 2023-12-11 16:10:41 -08:00
.gitignore Initial commit 2023-03-11 21:43:31 -08:00
McRule.sln TEST BROKEN - working on EF string comparisons. 2023-09-02 11:30:15 -07:00
README.md Updated readme and bumped version. 2024-04-23 16:11:08 -07:00
global.json Added solution file and updated filter extensions 2023-03-13 12:53:26 -07:00
license.txt Create license.txt 2023-03-11 21:47:27 -08:00

README.md

McRule

Rule based filtering using expression trees.

Predicate Grammar

Predicates are built using simple syntax to select comparison operators and methods for the specified properties on a supplied object of a specified type. That is the policy specifies the type by name, property to match against and the value the property must have. A simple equality comparison is used by default but operators can be prefixed to a policy operand for customized behavior, as shown below.

Property Type Operator Comparison Description
string * Astrisk can appear at the beginning, end or both denoting: StartsWith, EndsWith or Contains respectively.
string ~ Denotes case-insensitive comparison when used in .net, things that translate the resulting expression tree may not respect this. EF core for instance won't bind a Contains with case insensitive comparison from the string methods at all, results in a runtime error. Note: when used with wildcard, tilde operator must be first: '~*foo'.
string ! Negative expression. Must prefix all other operators.
IComparable > Greater-than comparison.
IComparable >= Greater-than or equal to comparison.
IComparable < Less-than comparison.
IComparable <= Less-than or equal to comparison.
IComparable <>, !=, ! Not-equal to comparison.

Note: the IComparable interface is mostly used for numerical types but custom types with comparison providers may work at runtime. Note: initial IDictionary support has been added but only for collections where the value types are strings. When missing keys are encountered, evaluation defaults to false.

Literal Values

Literal values, as needed, use handlbar syntax: {{ value }}. Null checks are implicitly added to most expressions but sometimes you need an expression that evaluates true for null values. In that case, a null literal is represented as {{null}}. Case sensitivity doesn't matter, nor does internal whitespace inside the braces. Values are interpretted like so:

var matched = handlebarPattern.Match(value);
if (matched.Success) {
    switch (matched.Groups.FirstOrDefault(x => x.Name == "literal")?.Value?.Trim()?.ToLower()) {
        case "null":
            return (true, new NullValue());
            break;
    }
}

Examples

Notes

Publish nuget package:

cd McRule/bin/Release
dotnet publish -c release ../../
dotnet nuget push McRule.0.0.5.nupkg --api-key <api key> --source https://api.nuget.org/v3/index.json