aqua.tool.Validation
3.0.1
See the version list below for details.
dotnet add package aqua.tool.Validation --version 3.0.1
NuGet\Install-Package aqua.tool.Validation -Version 3.0.1
<PackageReference Include="aqua.tool.Validation" Version="3.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add aqua.tool.Validation --version 3.0.1
#r "nuget: aqua.tool.Validation, 3.0.1"
// 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}()
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. |
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- PolySharp (>= 1.13.2)
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.1.0 | 155 | 10/15/2024 |
3.0.1 | 1,144 | 12/14/2023 |
3.0.0 | 309 | 12/12/2023 |
2.2.9 | 457 | 8/17/2023 |
2.2.8 | 224 | 8/15/2023 |
2.2.7 | 228 | 8/14/2023 |
2.2.4 | 211 | 8/8/2023 |
2.2.3 | 298 | 8/8/2023 |
2.2.1 | 284 | 8/3/2023 |
2.2.0 | 240 | 8/3/2023 |
2.1.1 | 207 | 7/31/2023 |
2.0.1 | 1,135 | 8/22/2022 |
2.0.0 | 854 | 12/1/2021 |
1.4.0 | 861 | 8/26/2021 |
1.3.0 | 277 | 8/24/2021 |
1.1.0 | 639 | 6/17/2021 |
1.0.1 | 378 | 5/6/2021 |
1.0.0 | 451 | 4/13/2021 |