Install RuleWright
RuleWright ships on NuGet. Add the main package to any project that targets .NET Framework 4.8, .NET Standard 2.0, .NET 8 or .NET 10.
Add the package
dotnet add package RuleWright
Check that it works
dotnet new console -n RulesHello
cd RulesHello
dotnet add package RuleWright
Replace Program.cs with this, and run it with dotnet run:
using RuleWright.Execution;
using RuleWright.Json.SystemText;
var engine = new RuleWrightBuilder()
.UseJsonReader(new SystemTextJsonReader())
.Build();
string rule = """{ "id": "hello", "condition": { "field": "Name", "operator": "IsNotNull" } }""";
Console.WriteLine($"RuleWright is ready: {engine.Validate(rule).IsValid}");
Output
RuleWright is ready: True
The namespaces you'll use
using RuleWright.Core; // Rule, RuleSet, EvaluationOptions, RuleEvaluationResult, FiredRule
using RuleWright.Execution; // RuleWrightBuilder, RuleWrightEngine, LoadedRuleSet
using RuleWright.Json.SystemText; // SystemTextJsonReader, SystemTextJsonFacts
using RuleWright.Serialization; // validation results, RuleSchemaCatalog, RuleHasher
using RuleWright.Extensions.Functions; // RegisterBuiltInFunctions, NamedRuleFunction
Editor support for rule files
The rule format has a formal JSON Schema. Point your editor at it and you get completion and inline errors while you write rules. Download rule-schema.json, or see The rule document format.
Next
Your first rule: build an engine, load a rule, and evaluate it.