StaticDotNet.ArgumentValidation 0.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package StaticDotNet.ArgumentValidation --version 0.3.0                
NuGet\Install-Package StaticDotNet.ArgumentValidation -Version 0.3.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="StaticDotNet.ArgumentValidation" Version="0.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StaticDotNet.ArgumentValidation --version 0.3.0                
#r "nuget: StaticDotNet.ArgumentValidation, 0.3.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 StaticDotNet.ArgumentValidation as a Cake Addin
#addin nuget:?package=StaticDotNet.ArgumentValidation&version=0.3.0

// Install StaticDotNet.ArgumentValidation as a Cake Tool
#tool nuget:?package=StaticDotNet.ArgumentValidation&version=0.3.0                

StaticDotNet.ArgumentValiation is a nullability annotation supported guard library with performance and ease of use in mind.

Installation

Package can install via NuGet and can be found at https://www.nuget.org/packages/StaticDotNet.ArgumentValidation.

Nullability annotations makes guard clauses pointless

While nullability annontations is a huge step forward in helping us developers write better applications (which we don't need as we get it right 100% of the time), it doesn't replace the need for guard clauses. And most of the guard libraries aren't able to fully support nullability annotations, which means you have to constantly ignore those warnings which really makes nullability annotations less helpful. And without them you have a bigger chance of getting the fun "Object not set to an instance of an object" error. If you haven't had to look at the stack trace, open a method of over 500 lines of code and tried to figure out what could possible be null in some random situation, you haven't lived.

If you are writing libraries that other developers/applications are using, your code has no way of knowing if nullability annontations are turned on. Or worse case those warnings are just ignored anyway. Not you of course, you are one of the good developers, hence why you are here.

Lastly nullability annotations only help with checking for null. It doesn't help with the other requirements that parameters have.

This is what validation is for

Validation is focused on the end user, guard clauses are focused on developers. This is a big difference and why guard clauses are still important. The point of a guard clause is to prevent a developer from doing something that will always result in an issue with the application. Validation is focused on helping the end user accomplish a specific work flow based on the business requirements while adhering to the limitations of the application. Both are important, but serve completely different purposes.

Performance

Since the point of guard clauses are to ensure the developer doesn't write bad code, ideally they should never throw an exception. This library is built around the idea that it should be just as fast as possible and avoid allocating any memory with the idea that the exception will not happen.

The library also fully supports trimming so you can only include the code that is actually used.

It also uses a readonly ref struct so as much as possible stays on the stack without copying the struct on every call.

Trimming

The library includes the specific attributes and analyzers to ensure it can be trimmed. This allows you to only include the validations that are used within you application when you enable trimming.

Writing guard clauses are ugly

Yes, writing guard clauses are ugly and they take up a lot of space. We all agree they are important but they take up too many lines of code and are ugly. Ok, maybe you don't agree, yet, but drink the Kool-Aid and I promise no space ships are involved.

The library is built using fluent syntax as that allows the developer a lot of flexibility with how they want to combine different argument validation. It is also built to only show the available validation methods for the specific argument type. For example, the NotWhiteSpace validation method is only shown in intellisense for string arguments.

Documentation

All documentation can be found at here.

Product 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 is compatible.  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 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.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
1.0.0 531 11/16/2023
0.6.5 693 7/31/2023
0.6.4 694 5/30/2023
0.6.3 696 5/29/2023
0.6.2 643 5/25/2023
0.6.1 682 5/19/2023
0.6.0 677 5/2/2023
0.5.3 698 4/7/2023
0.5.2 833 1/6/2023
0.5.1 824 12/22/2022
0.5.0 803 12/21/2022
0.4.0 824 12/20/2022
0.3.0 823 12/16/2022
0.2.0 804 12/16/2022
0.1.0 828 12/8/2022