Many.Validators
2.0.0-beta1
See the version list below for details.
dotnet add package Many.Validators --version 2.0.0-beta1
NuGet\Install-Package Many.Validators -Version 2.0.0-beta1
<PackageReference Include="Many.Validators" Version="2.0.0-beta1" />
paket add Many.Validators --version 2.0.0-beta1
#r "nuget: Many.Validators, 2.0.0-beta1"
// Install Many.Validators as a Cake Addin #addin nuget:?package=Many.Validators&version=2.0.0-beta1&prerelease // Install Many.Validators as a Cake Tool #tool nuget:?package=Many.Validators&version=2.0.0-beta1&prerelease
Many.Validators
A set of very-easy-to-read immutable types to add seamless validations in your projects.
I focused on:
- Less documentation, better code legibility.
- No extra line of code.
- [Extremely] easy integration.
- Minimum overhead compared to traditional copy-pasted-conditionals way or any other implementation.
👉Download releases at https://www.nuget.org/packages/Many.Validators/
Features
NetStandard 2.1 and NET60 specific implementations
- New Half type support for NET5 and NET6 projects.
Built-int validators and features
Validator | Implemented | Overhead* (baseline=1) | Version |
---|---|---|---|
NotNull<> | ✅ | 4.3 | 1.0.0 |
NotNullOrEmpty< string> | ✅ | 1.4 | 1.0.0 |
NotNullOrEmptyArray<> | ✅ | 2.0 - 2.3** | 1.1.0 |
Positive<> | ✅ | 1.3 - 2.1 | 1.0.0 |
PositiveOrZero<> | ✅ | 1.3 - 2.1 | 1.0.0 |
Negative<> | ✅ | 1.3 - 2.1 | 1.0.0 |
NegativeOrZero<> | ✅ | 1.3 - 2.1 | 1.0.0 |
InRange | ✅ | ❌ | 2.0.0-beta1 |
(*) This column shows the average overhead calculation in the validation-passes scenario that is the most expensive: we need to perform a validation and it passes. This is a measure of the overhead cost, not the cost itself. The baseline corresponds to the simplest way to validate each case (copy-pasted IF conditional(s) and manual exception throwing). Data is provided from supported frameworks but in this table the value is from NET60 benchmarks. <br>Results for older frameworks can vary depending the framework (generally older the framework a bit worse the result) and if you force conversions or not (you can check the complete results at Many.Validators.Benchmark/Data).
Feature | Implemented | Version |
---|---|---|
Validators concatenation | ❌ | ? |
Two-way conversion between validator and underlying types
NotNull<string> notMullStringValidator = "whatever"; //Ok
string x = notMullStringValidator; //Ok
notMullStringValidator.Equals(x); //true!
Seamless integration
Use validators in your methods referring your underlying type:
bool WhateverMethod(NotNull<string> @param)
{
//@param is observed and validated when is instantiated.
//If validation fails no line of code will be run in this method
Console.WriteLine("Whatever");
//Gets @param value with no conversion
return !string.IsNullOrWhiteSpace(@param);
}
And call your methods as usual with no additional conversions:
string p;
<Code where you can assign a value to p or not...>
var result = WhateverMethod(p);
<Continues if no exception was raised...>
InRange validators
InRange validators need a range 😅. To get that you only need to create your custom range class (inherit from abstract RangeBase class) and implement the abstract properties. Finally be sure to name your class with a self-descritive name.
Example:
namespace YourProject.Validators.Ranges.Int64
{
internal class Neg100_1 : Range<Int64>
{
public override long Max => 1;
public override long Min => -100;
}
}
Then only use it:
public void DoSometing(InRange<Neg100_1, Int64> param1)
{
...
}
Tip: Also you can follow a self-descriptive namespace naming strategy in order to get clearer shorter range names.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
All Frameworks
- Microsoft.CSharp (>= 4.7.0)
-
net6.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.
v.2.0.0-beta1
- Added: InRange validator
v.1.1.0
- Added: NotNullOrEmpty(string) and NotNullOrEmptyArray
v.1.0.4
- NotNull, NotEmpty, Positive, PositiveOrZero, Negative and NegativeOrZero validators.