A C# library that provides a fluent-api for basic argument validation.
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]).
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()
);Versions follow the semantic versioning scheme.
ZySharp.Validation is licensed under the MIT license.