aqua.tool.Validation 3.0.1

dotnet add package aqua.tool.Validation --version 3.0.1
NuGet\Install-Package aqua.tool.Validation -Version 3.0.1
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="aqua.tool.Validation" Version="3.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add aqua.tool.Validation --version 3.0.1
#r "nuget: aqua.tool.Validation, 3.0.1"
#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 aqua.tool.Validation as a Cake Addin
#addin nuget:?package=aqua.tool.Validation&version=3.0.1

// Install aqua.tool.Validation as a Cake Tool
#tool nuget:?package=aqua.tool.Validation&version=3.0.1

What is it? 🚀

aqua.tool.Validation provides C# source generated extension methods for argument validation.

This package is designed to work for various target frameworks and makes use of PolySharp to integrate with different C# language versions.

How to Use

public void SampleMethod(string text)
{
  // Throw an ArgumentNullException if text is null.
  // Throw an ArgumentException if text is empty.
  text.AssertNotNullOrEmpty();
}

public void SampleMethod(IReadOnlyList<string> text)
{
  // Throw an ArgumentNullException if text is null.
  // Throw an ArgumentException if any element in text is null or empty.
  text.AssertItemsNotNullOrEmpty();
}

Assert vs. Check

Most validation methods exists in two flavors. While assert simply verifies the input (e.g. AssertNotNull), check also returns the input value to allow for fluent API style code (e.g. CheckNotNull).

Migrate validation code for version 2.2.0 and later

Starting with aqua.tool.Validation v2.2.0 the name argument can be omitted as it's atomatically injected by the compiler using the CallerArgumentExpressionAttribute. Existing code can easily be migrated using regex find and replace in Visual Studio:

  • Search regex pattern:

    \.(?<method>((Assert)|(Check))(Items)?NotNull(OrEmpty)?)\(((nameof\([^\)]+\))|([^\)]+))\)
    
  • Replace regex pattern:

    .${method}()
    

    migrate validation code

Options

Code generation can be configured through some MSBuild properties to set in consuming projects.

Property Value Description
AquaToolValidationDisable true|false Disable compilation of generated source code.
AquaToolValidationPublic true|false Declare generated source code as public. By default, generated source code has internal visibility.
AquaToolValidationNullableDisable true|false Suppress nullable attributes.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on aqua.tool.Validation:

Repository Stars
6bee/Remote.Linq
Simply LINQ your remote resources...
Version Downloads Last updated
3.0.1 522 12/14/2023
3.0.0 248 12/12/2023
2.2.9 391 8/17/2023
2.2.8 182 8/15/2023
2.2.7 189 8/14/2023
2.2.4 170 8/8/2023
2.2.3 254 8/8/2023
2.2.1 243 8/3/2023
2.2.0 203 8/3/2023
2.1.1 183 7/31/2023
2.0.1 1,101 8/22/2022
2.0.0 824 12/1/2021
1.4.0 834 8/26/2021
1.3.0 253 8/24/2021
1.1.0 611 6/17/2021
1.0.1 351 5/6/2021
1.0.0 417 4/13/2021