CSharpEssentials.Rules 3.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSharpEssentials.Rules --version 3.0.3
                    
NuGet\Install-Package CSharpEssentials.Rules -Version 3.0.3
                    
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="CSharpEssentials.Rules" Version="3.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpEssentials.Rules" Version="3.0.3" />
                    
Directory.Packages.props
<PackageReference Include="CSharpEssentials.Rules" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSharpEssentials.Rules --version 3.0.3
                    
#r "nuget: CSharpEssentials.Rules, 3.0.3"
                    
#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.
#:package CSharpEssentials.Rules@3.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSharpEssentials.Rules&version=3.0.3
                    
Install as a Cake Addin
#tool nuget:?package=CSharpEssentials.Rules&version=3.0.3
                    
Install as a Cake Tool

CSharpEssentials.Rules

Composable, functional rule engine for .NET. Define business logic as small, reusable rules and combine them with a fluent API.

Features

  • Simple Rules — Implement IRule<TContext> or use Func<TContext, Result>.ToRule().
  • Linear Sequences — Run rules in order, stop on first failure.
  • Conditional Rules — If/Then/Else branching.
  • And / Or Logic — All must pass, or at least one must pass.
  • Async Support — First-class async rules.
  • Result Integration — Built on CSharpEssentials.Results.

Installation

dotnet add package CSharpEssentials.Rules

Usage

Defining Rules

using CSharpEssentials.Rules;
using CSharpEssentials.ResultPattern;
using CSharpEssentials.Errors;

public class AgeRule : IRule<UserContext>
{
    public Result Evaluate(UserContext ctx, CancellationToken ct = default)
    {
        if (ctx.Age < 18)
            return Error.Validation("Age.Underage", "Must be at least 18.");
        return Result.Success();
    }
}

// Or with a Func
IRule<UserContext> licenseRule = (Func<UserContext, Result>)(ctx =>
    ctx.HasLicense ? Result.Success() : Error.Validation("License.Missing", "License required.")).ToRule();

Evaluating Rules

var ctx = new UserContext { Age = 20, HasLicense = true };
Result result = RuleEngine.Evaluate(new AgeRule(), ctx);

Combining Rules

// All must pass
Result andResult = RuleEngine.And(new[] { new AgeRule(), licenseRule }, ctx);

// At least one must pass
Result orResult = RuleEngine.Or(new[] { passportRule, licenseRule }, ctx);

// Sequence (stop on first failure)
Result linear = RuleEngine.Linear(new[] { step1, step2, step3 }, ctx);

// Conditional
Result conditional = RuleEngine.If(new AgeRule(), new GrantAccessRule(), new DenyAccessRule(), ctx);

Rules with Values

IRule<int, string> gradeRule = ((Func<int, Result<string>>)(score =>
{
    if (score >= 90) return "A";
    if (score >= 80) return "B";
    return Error.Validation("Grade", "Failed.");
})).ToRule();

Result<string> grade = gradeRule.Evaluate(85);
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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
.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 (1)

Showing the top 1 NuGet packages that depend on CSharpEssentials.Rules:

Package Downloads
CSharpEssentials

A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.5 121 5/7/2026
3.0.4 114 5/6/2026
3.0.3 120 5/5/2026
3.0.2 130 5/5/2026
3.0.1 134 5/3/2026
3.0.0 125 5/3/2026
2.1.0 298 11/26/2025
2.0.9 247 9/30/2025
2.0.8 219 9/29/2025
2.0.7 223 9/29/2025
2.0.6 222 9/29/2025
2.0.5 219 9/29/2025
2.0.4 220 9/28/2025
2.0.3 235 9/28/2025
2.0.2 230 9/28/2025
2.0.1 225 9/28/2025
2.0.0 221 9/28/2025