A simple library write in .NET (C#) to validate your staff without nesting your code.
using Validation;
object myValue = null;
myValue.Validate().NotBeNull("This fail because myValue is null.");
This library is inspired by two great libraries: FluentValidation and FluentAssertions.
With DirectValidation you can use a simple and direct code style to validate your variables, properties, etc, without worry about nesting your code with if, else. Just call your validation directly.
We use the fail first design. This means that if your validation don't pass an exception are thrown immediately:
using Validation;
var myValue = "foo";
myValue.Validate().Be("bar", "myValue is not bar.");
DirectValidation can be installed using the Nuget package manager or the dotnet
CLI.
Install-Package DirectValidation
Just add Validation to your using list and call Validate() method in any type of value to access the validation methods.
using Validation;
var myValue = "foo";
myValue.Validate().NotBeNullOrWhiteSpace().NotBe("bar").Be("foo"); // etc
All validation methods receives a message and an args parameters to format your fail message using string.format().
Every type has your own validations, a bunch of that, I put the most commons. If your feel some other is missing, just send a PR to this repository, I appreciate.
I implement most validations found in FluentValidation and FluentAssertions, so you can found there what I talk about.
DirectValidation has adopted Apache License, so you can use this freely to all-purpose.