AoK.FluentValidation
1.2.0
See the version list below for details.
dotnet add package AoK.FluentValidation --version 1.2.0
NuGet\Install-Package AoK.FluentValidation -Version 1.2.0
<PackageReference Include="AoK.FluentValidation" Version="1.2.0" />
paket add AoK.FluentValidation --version 1.2.0
#r "nuget: AoK.FluentValidation, 1.2.0"
// Install AoK.FluentValidation as a Cake Addin #addin nuget:?package=AoK.FluentValidation&version=1.2.0 // Install AoK.FluentValidation as a Cake Tool #tool nuget:?package=AoK.FluentValidation&version=1.2.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 validator.Error
return;
}
}
Learn more about Target Frameworks and .NET Standard.
This package has 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 libraries for Any CPU, x86 and x64