CSharpEssentials.Rules
3.0.2
See the version list below for details.
dotnet add package CSharpEssentials.Rules --version 3.0.2
NuGet\Install-Package CSharpEssentials.Rules -Version 3.0.2
<PackageReference Include="CSharpEssentials.Rules" Version="3.0.2" />
<PackageVersion Include="CSharpEssentials.Rules" Version="3.0.2" />
<PackageReference Include="CSharpEssentials.Rules" />
paket add CSharpEssentials.Rules --version 3.0.2
#r "nuget: CSharpEssentials.Rules, 3.0.2"
#:package CSharpEssentials.Rules@3.0.2
#addin nuget:?package=CSharpEssentials.Rules&version=3.0.2
#tool nuget:?package=CSharpEssentials.Rules&version=3.0.2
CSharpEssentials.Rules
CSharpEssentials.Rules is a composable, functional rule engine for .NET. It allows you to define business logic as small, reusable rules and combine them into complex workflows using a fluent API.
🚀 Features
- Composable Logic: Build complex logic from simple, single-responsibility rules.
- Flow Control: Support for Linear (sequences), Conditional (If/Else), And, and Or rule combinations.
- Async Support: First-class support for asynchronous rules.
- Result Pattern: Built on top of
CSharpEssentials.Resultsto return success/failure status. - Context-Driven: Rules operate on a shared
TContextstate.
📦 Installation
dotnet add package CSharpEssentials.Rules
🛠 Usage
1. Defining Rules
You can implement the IRule<TContext> interface or use functional adapters.
Using Interface:
using CSharpEssentials.Rules;
using CSharpEssentials.ResultPattern;
public class UserContext
{
public int Age { get; set; }
public bool HasLicense { get; set; }
}
public class AgeRule : IRule<UserContext>
{
public Result Evaluate(UserContext context, CancellationToken ct = default)
{
if (context.Age < 18)
return Result.Failure("User.Underage", "User must be at least 18.");
return Result.Success();
}
}
Using Func:
Func<UserContext, Result> licenseCheck = ctx =>
ctx.HasLicense
? Result.Success()
: Result.Failure("User.NoLicense", "User must have a license.");
var rule = licenseCheck.ToRule();
2. Executing Rules
Use the RuleEngine to evaluate a rule against a context.
var context = new UserContext { Age = 20, HasLicense = true };
var rule = new AgeRule();
Result result = RuleEngine.Evaluate(rule, context);
if (result.IsSuccess)
{
Console.WriteLine("Rule passed!");
}
3. Composing Rules (Linear)
Run rules in a sequence. If one fails, execution stops.
var complexRule = Rule.Linear(new AgeRule())
.Next(licenseCheck.ToRule());
Result result = RuleEngine.Evaluate(complexRule, context);
4. Conditional Rules
Execute different rules based on the result of a condition.
var workflow = Rule.If(new AgeRule(),
then: new GrantAccessRule(),
@else: new DenyAccessRule());
5. And / Or Logic
Combine multiple rules.
- And: All rules must pass.
- Or: At least one rule must pass.
var combined = Rule.And(
new AgeRule(),
new CitizenshipRule()
);
var alternative = Rule.Or(
new PassportRule(),
new DriverLicenseRule()
);
| 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.2)
- CSharpEssentials.Results (>= 3.0.2)
- System.Text.Json (>= 9.0.0)
-
net10.0
- CSharpEssentials.Core (>= 3.0.2)
- CSharpEssentials.Results (>= 3.0.2)
-
net11.0
- CSharpEssentials.Core (>= 3.0.2)
- CSharpEssentials.Results (>= 3.0.2)
-
net9.0
- CSharpEssentials.Core (>= 3.0.2)
- CSharpEssentials.Results (>= 3.0.2)
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 |