Argument.Check 4.0.1

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

// Install Argument.Check as a Cake Tool
#tool nuget:?package=Argument.Check&version=4.0.1                

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 Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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 (1)

Showing the top 1 popular GitHub repositories that depend on Argument.Check:

Repository Stars
shadowsocks/Shadowsocks-Net
✈ A light-weight, cross-platform, extensible Shadowsocks developed in C# (.NET Core).
Version Downloads Last updated
5.0.0 168 11/20/2024
4.0.2 811 11/20/2024
4.0.1 144 9/6/2024
4.0.0 36,973 11/28/2023
3.0.1 29,828 5/29/2023
3.0.0 90 5/29/2023
2.0.0 19,184 7/25/2022
2.0.0-alpha.59 403 7/3/2022
2.0.0-alpha.58 148 7/3/2022
2.0.0-alpha.52 7,637 10/19/2021
1.0.4 257,652 1/19/2020
1.0.3 1,079 1/18/2020
1.0.2 1,091 1/18/2020
1.0.1 26,905 1/3/2020
1.0.0 526 1/3/2020
0.9.0 5,733 12/26/2019

Changes:
           - Upgrade to Net8