ThrowIfArgument 1.1.0

dotnet add package ThrowIfArgument --version 1.1.0                
NuGet\Install-Package ThrowIfArgument -Version 1.1.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="ThrowIfArgument" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ThrowIfArgument --version 1.1.0                
#r "nuget: ThrowIfArgument, 1.1.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 ThrowIfArgument as a Cake Addin
#addin nuget:?package=ThrowIfArgument&version=1.1.0

// Install ThrowIfArgument as a Cake Tool
#tool nuget:?package=ThrowIfArgument&version=1.1.0                

ThrowIfArgument

NuGet Status NuGet

This is just another guard clause library for validating your arguments, but I enjoy the way using this API reads quite fluently. If you're like me, then you've been recreating a library of guard clauses from company to company. I finally got tired and uploaded my own version of a guard clause library.

This library is very similar to Guard Clauses, which I highly recommend checking out. It is well reviewed and has active support.

NuGet Installation

Install the ThrowIfArgument NuGet package:

dotnet add package ThrowIfArgument

Usage

public void HelloWorld(FooBar fooBar)
{
    ThrowIf.Argument.IsNull(fooBar);
    
    Console.WriteLine($"The narwhal bacons at {fooBar.BaconsAt}");
}

Extensibility

If you feel the package is missing a feature, you can extend with your own features:

public static ThrowIfArgumentExtensions
{
    public static string StartsWithThunderclap
    (
        this IThrowIfArgumentBuilder,
        string argument,
        string? message = null,
        [CallerArgumentExpression("argument")] string? argumentName = null
    )
    {
        if (!argument.StartsWith("thunderclap", StringComparison.OrdinalIgnoreCase))
        {  
            return argument;
        }
        
        throw new ArgumentException(
            string.IsNullOrWhiteSpace(message)
                ? $"Cannot start with 'thunderclap'."
                : message,
            argumentName);        
    }
}

Ping me if you want any new features added to the library ❤️

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ThrowIfArgument:

Package Downloads
AutoIoc

Easily add dependencies to your dependency injection container with attributes. This includes services, options, and HTTP clients.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 2,253 5/29/2024
1.0.3 16,185 12/9/2022
1.0.2 871 12/7/2022
1.0.1 316 12/7/2022
1.0.0 318 12/6/2022
0.0.0-alpha04 115 12/6/2022
0.0.0-alpha03 159 12/2/2022
0.0.0-alpha02 119 12/2/2022
0.0.0-alpha01 158 12/2/2022

Support .NET 8