Viya.RuleEngine
0.4.1
dotnet add package Viya.RuleEngine --version 0.4.1
NuGet\Install-Package Viya.RuleEngine -Version 0.4.1
<PackageReference Include="Viya.RuleEngine" Version="0.4.1" />
paket add Viya.RuleEngine --version 0.4.1
#r "nuget: Viya.RuleEngine, 0.4.1"
// Install Viya.RuleEngine as a Cake Addin #addin nuget:?package=Viya.RuleEngine&version=0.4.1 // Install Viya.RuleEngine as a Cake Tool #tool nuget:?package=Viya.RuleEngine&version=0.4.1
RuleEngine
With RuleEngine you can write rules, which consist of an expression and a patch definition, to modify a object/model.
These rules
can be defined in yaml
or with typed C# objects.
Release Notes
Please see the changelog!
Example
Provided the following input object
Name: Henk
Age: 15
Phone: 0612345678
Address:
StreetName: Hoofdstraat
StreetNumber: 25a
City: Amsterdam
PostalCode: 1234AA
WorkAddress: null # Same type/fields as Address
Replacing a single property
rules:
- condition: Age < 16
patch:
Age: 25
The condition Age < 16
evaluates to: true
Thus the Age
property becomes: 25
Replacing multiple properties at once (merge)
rules:
- condition: Phone.StartsWith("06")
patch:
Phone: 0612341234
Address:
City: Hilversum
The condition Phone.StartsWith("06")
evaluates to: true
Thus the Phone
property becomes 0621341234
and Address.City
becomes Hilversum
Using lambda expressions in assignments
With a Lambda expression it is possible to use logic to assign the object, take a look at the following examples.
patch:
myProperty1: input => input.Name # referencing the input object
myProperty2: x => $"prefix-{x.Name}-postfix" # using a custom identifier with string interpolation
myYear: _ => DateTime.Now.Year # omitting the input object and using DateTime C# class
Copy-ing properties from the input object
rules:
- condition: true
patch: # copy to child object (not null)
WorkAddress: input => input.Address
Here the condition is true
The result becomes:
Name: Henk
Age: 15
Phone: 0612345678
Address:
StreetName: Hoofdstraat
StreetNumber: 25a
City: Amsterdam
PostalCode: 1234AA
WorkAddress:
StreetName: Hoofdstraat
StreetNumber: 25a
City: Amsterdam
PostalCode: 1234AA
Finding the best tool for the job
Running a benchmark
dotnet run -c Release --project RuleEngine.Benchmark
Results:
Resources
All this was not possible without the following libraries:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CodingSeb.ExpressionEvaluator (>= 1.4.39)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.1)
- Newtonsoft.Json (>= 13.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.