didii.FluentValidator 0.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package didii.FluentValidator --version 0.0.0
NuGet\Install-Package didii.FluentValidator -Version 0.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="didii.FluentValidator" Version="0.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add didii.FluentValidator --version 0.0.0
#r "nuget: didii.FluentValidator, 0.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install didii.FluentValidator as a Cake Addin
#addin nuget:?package=didii.FluentValidator&version=0.0.0

// Install didii.FluentValidator as a Cake Tool
#tool nuget:?package=didii.FluentValidator&version=0.0.0

FluentValidator

Motivation

When validating business logic, there is typically no single place where validation happens and error messages are often hard-coded and linked to each other, hard to read or don't provide enough info. This library aims to alleviate this by using C# expression tree's to dynamically generate the correct data.

Usage

When using the following objects:

public class Foo {
    public long Id { get; set; }
    public string Name { get; set; }
    public long BarId { get; set; }
    public Bar Bar { get; set; }
}

public class Bar {
    public long Id { get; set; }
    public string Name { get; set; }
}

you would be able to provide the following validation rules

//Create a validationbuilder instance
IValidationBuilder<Foo> validator = new ValidationBuilder();
//or if you want to skip calling Start
IValidationBuilder<Foo> validator = new ValidatoinBuilder(foo);

var messages = validator.Start(foo) //<- skip if you used the second constructor
                        //Name must be non-null and non-empty value
                        .Require(o => o.Name)
                        //Name must have a length between 2 and 50 (inclusive)
                        .Length(o => o.Name, min: 2, max: 50)
                        //A custom check
                        .Check(o => o.Name != "forbidden name")
                        //At least one of the following properties must be non-null and non-zero
                        .RequireAny(o => o.ParentId, o => o.Parent)
                        //Nested property
                        .Require(o => o.Bar.Name)
                        //Changes all following validation calls to warning
                        //this will still add the messages to the end-result, but won't change
                        //the value of messages.Success
                        .AsWarning()
                        //If ID is a null or zero value, add it
                        .Require(o => o.Id)
                        //Needs to be called to expose the validation messages
                        .Build();

if (!messages.Success) {
    foreach (var message in messages)
        //handle message
} else {
    //handle success
}
//...

Known issues / roadmap

  • Does not support LINQ yet: o.MyIEnumerable.All(e => e.Foo != null) will view o.MyIEnumerable and e.Foo as 2 different properties and will not combine them to o.MyIEnumerable.Foo.
  • The method RequireAny only supports up to 4 expressions and is currently very badly implemented
  • The expression tree is evaluated every time the validation executes. This should be changed so you can build up metadata either at the start of the application or when the validation first runs and even better assign validation rules to a type rather than an instance of an object.
Product 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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.0

    • 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.

Version Downloads Last updated