Many.Validators
3.0.0
See the version list below for details.
dotnet add package Many.Validators --version 3.0.0
NuGet\Install-Package Many.Validators -Version 3.0.0
<PackageReference Include="Many.Validators" Version="3.0.0" />
paket add Many.Validators --version 3.0.0
#r "nuget: Many.Validators, 3.0.0"
// Install Many.Validators as a Cake Addin #addin nuget:?package=Many.Validators&version=3.0.0 // Install Many.Validators as a Cake Tool #tool nuget:?package=Many.Validators&version=3.0.0
Many.Validators
A set of very-easy-to-read immutable types to add seamless validations in your projects.
Focused on:
- Less documentation, better code legibility.
- No extra line of code, just change type by validators and that's all.
- Minimum overhead compared to traditional copy-pasted-conditionals way or any other implementation.
👉Download releases at https://www.nuget.org/packages/Many.Validators/
Features
Built-int validators and features
Validator | Implemented | Version |
---|---|---|
NotNull<> | ✅ | 1.0.0 |
NotNullOrEmpty< string> | ✅ | 1.0.0 |
NotNullOrEmptyArray<> | ✅ | 1.1.0 |
Positive<> | ✅ | 1.0.0 |
PositiveOrZero<> | ✅ | 1.0.0 |
Negative<> | ✅ | 1.0.0 |
NegativeOrZero<> | ✅ | 1.0.0 |
InRange | ✅ | 2.0.0 |
Feature | Implemented | Version |
---|---|---|
Multiple explicit validation | ✅ | 3.0.0 |
Validators concatenation | ❌ | ? |
✅Two-way conversion between validator and underlying types
NotNull<string> notNullStringValidator = "whatever"; //Ok
string x = notNullStringValidator; //Ok
notNullStringValidator.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.
✅ Multiple explicit validations
Also you can validate in a explicit way. If you have a class like this:
class YourObject
{
public string Id {get;set;}
public string Data {get;set;}
}
You can use it in your code to validate it content in serveral ways:
public void DoSomething(NotNull<YourObject> param) //This line checks if param itself is not null
{
var otherParamsToCheck = new string[]{param.Id, param.Data};
//You can validate params and get an exception if any fails validation or...
NotNull<string>.Validate(otherParamsToCheck);
//...you can validate params and get the result with no exceptions
//Get all errors
var result = NotNull<string>.IsValid(otherParamsToCheck, out string[] errors);
//Get and stop after first error
result = NotNull<string>.IsValid(otherParamsToCheck, out string error);
}
✅ NetStandard 2.1 and NET60 specific implementations
- New Half type support for NET5 and NET6 projects.
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.3.0.0
- Added: Multiple explicit validations
v.2.0.0
- Added: InRange validator
v.1.1.0
- Added: NotNullOrEmpty(string) and NotNullOrEmptyArray
v.1.0.4
- NotNull, NotEmpty, Positive, PositiveOrZero, Negative and NegativeOrZero validators.