Viya.RuleEngine 0.4.1

dotnet add package Viya.RuleEngine --version 0.4.1
NuGet\Install-Package Viya.RuleEngine -Version 0.4.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Viya.RuleEngine" Version="0.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Viya.RuleEngine --version 0.4.1
#r "nuget: Viya.RuleEngine, 0.4.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

NuGet version (Viya.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.1 1,832 1/9/2023
0.4.0 304 1/9/2023
0.3.2 346 12/19/2022
0.3.1 424 12/19/2022
0.3.0 264 12/19/2022
0.2.0 294 12/15/2022
0.1.3 427 12/13/2022
0.1.2 272 12/13/2022
0.1.1 267 12/12/2022
0.1.0 258 12/12/2022