CSharpEssentials.Rules
3.0.3
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
<PackageReference Include="CSharpEssentials.Rules" Version="3.0.3" />
<PackageVersion Include="CSharpEssentials.Rules" Version="3.0.3" />
<PackageReference Include="CSharpEssentials.Rules" />
paket add CSharpEssentials.Rules --version 3.0.3
#r "nuget: CSharpEssentials.Rules, 3.0.3"
#:package CSharpEssentials.Rules@3.0.3
#addin nuget:?package=CSharpEssentials.Rules&version=3.0.3
#tool nuget:?package=CSharpEssentials.Rules&version=3.0.3
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 useFunc<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 | 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. 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. |
-
.NETStandard 2.1
- CSharpEssentials.Core (>= 3.0.3)
- CSharpEssentials.Results (>= 3.0.3)
- System.Text.Json (>= 9.0.0)
-
net10.0
- CSharpEssentials.Core (>= 3.0.3)
- CSharpEssentials.Results (>= 3.0.3)
-
net11.0
- CSharpEssentials.Core (>= 3.0.3)
- CSharpEssentials.Results (>= 3.0.3)
-
net9.0
- CSharpEssentials.Core (>= 3.0.3)
- CSharpEssentials.Results (>= 3.0.3)
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 |