Skip to content

A C# library that provides a fluent-api for basic argument validation.

License

Notifications You must be signed in to change notification settings

zysharp/validation

Repository files navigation

ZySharp Validation

License: MIT Build Quality Gate Status Coverage NuGet Nuget

A C# library that provides a fluent-api for basic argument validation.

Introduction

The ZySharp Validation library is intended to replace repetitive validation/guarding code at the begin of public methods. Contrary to e.g. FluentValidation it is not designed to validate complex entities or to report meaningful validation messages to users.

In case of a validation failure, an exception is thrown immediately without performing any further validations. The exception does always contain the root argument name as well as the complete path of the property that caused the validation to fail (e.g. assembly.Location or ids[i]).

Fluent API

ZySharp Validation provides a fluent API to validate arguments:

ValidateArgument.For(args, nameof(args), v => v
    .NotNull()
    .NotEmpty()
    ...
);

Validations of sub-properties or collections are executed in separate contexts:

ValidateArgument.For(args, nameof(args), v => v
    .NotNull()
    .For(x => x.SubProperty, v => v // <- Switch to sub-property context
        .NotEmpty()
        .InRange(1, 100)
    )                               // <- Switch back to the original context
    .NotEmpty()
);

Versioning

Versions follow the semantic versioning scheme.

License

ZySharp.Validation is licensed under the MIT license.

About

A C# library that provides a fluent-api for basic argument validation.

Resources

License

Stars

Watchers

Forks

Languages