AoK.FluentValidation
1.1.0
See the version list below for details.
dotnet add package AoK.FluentValidation --version 1.1.0
NuGet\Install-Package AoK.FluentValidation -Version 1.1.0
<PackageReference Include="AoK.FluentValidation" Version="1.1.0" />
paket add AoK.FluentValidation --version 1.1.0
#r "nuget: AoK.FluentValidation, 1.1.0"
// Install AoK.FluentValidation as a Cake Addin #addin nuget:?package=AoK.FluentValidation&version=1.1.0 // Install AoK.FluentValidation as a Cake Tool #tool nuget:?package=AoK.FluentValidation&version=1.1.0
About AoK.FluentValidation addresses the issue of high cyclomatic complexity that arises from validations (parameters or otherwise) that are peformed as fail-fast before performing the function. In case of parameter validations, the cyclomatic complexity would become minimally (n + 1), where n is the number of parameters to be validated. AoK.FluentValidation, apart from helping you to write validation code fluently, reduces the complexity of such code to 2 irrespective of the number of parameters to be validated.
Usage
// Conventional
void ValidateParameters(SomeClass obj, int percent, string message)
{
if(obj == null)
{
// print error
return;
}
if(percent < 0 || percent > 100) // Cyclomatic complexity >= 4
{
// print error
return;
}
if(string.IsNullorEmpty(message))
{
// print error
return;
}
}
// AoK.FluentValidation
void ValidateParameters(SomeClass obj, int percent, string message)
{
IValidator validator =
ValidatorBuilder
.WithValidation(() => obj != null)
.AndFailureMessage("{nameof(obj)} cannot be null")
.AndWithValidation(() => percent >= 0 && percent <= 100)
.AndFailureMessage("{nameof(percent)} shall be in range 0..100") // cyclomatic complexity <= 3
.AndWithValidation(() => !string.IsNullorEmpty(message))
.AndFailureMessage("{nameof(message)} shall not be null or empty")
.Build();
// validation
if(!validator.IsValid())
{
// print validaor.Error
return;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added Readme.md file