DsRule stands for Domain-specific Rule.
DsRule is used to parse domain-specific expression (in string) to Linq Expression and execute.
dotnet add package DsRule
The simplest case is parsing below expression
var result = DsRuleExecutor.Execute<int>("1 + 1");
// result is 2
A more complicated example for domain-specific expression
var model = new Employee { FirstName = "Vincent", LastName = "Any", Age = 30 };
var dsExpr = "FirstName = 'Vincent' AND Age > 25";
var result = DsRuleExecutor.Execute<Employee, bool>(model, dsExpr);
// 'result' is true
You can also use expresion in Where caluse
var employees = new List<Employee> { ... }; // A list of employees
var filtered = employees.Where("FirstName = 'Vincent' AND Age > 25");
For more examples, please refer to Examples
Kind | -- | Description |
---|---|---|
Comparand | +, -, *, / | |
Comparison | <, >, <=, >=, =, !=, <> | |
Keyword | not, and, or, true, false, null | |
Keyword | in | Used for Array |
Keyword | now, today | Will be parsed to DateTime.Now and DateTime.Today |