Argument.Check
5.0.0
dotnet add package Argument.Check --version 5.0.0
NuGet\Install-Package Argument.Check -Version 5.0.0
<PackageReference Include="Argument.Check" Version="5.0.0" />
paket add Argument.Check --version 5.0.0
#r "nuget: Argument.Check, 5.0.0"
// Install Argument.Check as a Cake Addin #addin nuget:?package=Argument.Check&version=5.0.0 // Install Argument.Check as a Cake Tool #tool nuget:?package=Argument.Check&version=5.0.0
Argument.Check
Argument.Check is a very simple library which makes it very easy to check your arguments or variables for different conditions like 'Null'. It is super fast it is using the new [CallerMemberNameAttribute]
Getting started
Prerequisites
Install the package
dotnet add package Argument.Check
Samples
Each Throw helper could also be used like a "Throw Expression".
Null check
public MyClass(object arg)
{
Throw.IfNull(arg);
}
Null check, like 'Throw Expressions'
public MyClass(IService service)
{
_service = Throw.IfNull(service);
}
Null check on a stack variable
public MyClass(IService service)
{
Throw.IfNull(service);
var result = service.GetSomething();
Throw.IfNull(result);
}
File exists
public MyClass(FileInfo fileInfo)
{
Throw.IfExists(fileInfo);
}
Directory exists
public MyClass(DirectoryInfo directoryInfo)
{
Throw.IfExists(directoryInfo);
}
Value is greater than
public MyClass(int value)
{
Throw.IfGreaterThan(value, 10);
}
Value is less than
public MyClass(int value)
{
Throw.IfLessThan(value, 10);
}
Value is out of range
public MyClass(int value)
{
Throw.IfOutOfRange(value, 10, 100);
}
Custom expression
public MyClass(string value)
{
Throw.If(value, v => v.Length > 10 && v.Contains("abc"), "The given string length must not be longer than 10, and must not contain 'abc'");
}
Argument must be an interface
public MyClass(object value)
{
Throw.IfNotInterface(value);
}
Argument must be equal to any expectation
public MyClass(object value)
{
Throw.IfNotEqualsTo(value, new object());
}
And many more.
public MyClass(object value)
{
Throw.If(...)
Throw.IfNot(...)
Throw.IfNull(...)
Throw.IfEmpty(...)
Throw.IfNotEmpty(...)
Throw.IfTypeIs(...)
Throw.IfTypeIsNot(...)
Throw.IfEqualsTo(...)
Throw.IfNotEqualsTo(...)
Throw.IfExists(...)
Throw.IfNotExists(...)
Throw.IfGreaterOrEqual(...)
Throw.IfGreaterThan(...)
Throw.IfLessOrEqual(...)
Throw.IfLessThan(...)
Throw.IfInterface(...)
Throw.IfNotInterface(...)
Throw.IfLengthIs(...)
Throw.IfLengthIsNot(...)
Throw.IfContains(...)
Throw.IfNotContains(...)
Throw.IfNullOrAny(...)
Throw.IfNullOrAnyItemIsNull(...)
Throw.IfNullOrEmpty(...)
Throw.IfNullOrWhiteSpace(...)
Throw.IfOutOfRange(...)
Throw.IfWhitespace(...)
Throw.IfAnyItemIsNullOrWhitespace(...)
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Argument.Check:
Package | Downloads |
---|---|
Extensions.Pack
A set of useful extensions to make your code smooth and nice readable. |
|
CSharp.Parser.Abstraction
A simple abstraction to parse C# files. Target should be a human friendly readable result. But it is just based on the syntax tree. You don't get any semantic informations. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0 | 77 | 11/20/2024 |
4.0.2 | 95 | 11/20/2024 |
4.0.1 | 115 | 9/6/2024 |
4.0.0 | 29,297 | 11/28/2023 |
3.0.1 | 26,582 | 5/29/2023 |
3.0.0 | 84 | 5/29/2023 |
2.0.0 | 19,141 | 7/25/2022 |
2.0.0-alpha.59 | 399 | 7/3/2022 |
2.0.0-alpha.58 | 142 | 7/3/2022 |
2.0.0-alpha.52 | 7,633 | 10/19/2021 |
1.0.4 | 230,535 | 1/19/2020 |
1.0.3 | 1,070 | 1/18/2020 |
1.0.2 | 1,082 | 1/18/2020 |
1.0.1 | 26,895 | 1/3/2020 |
1.0.0 | 518 | 1/3/2020 |
0.9.0 | 5,725 | 12/26/2019 |
Changes:
- Upgrade to Net8