ThrowIfArgument 2.0.0
dotnet add package ThrowIfArgument --version 2.0.0
NuGet\Install-Package ThrowIfArgument -Version 2.0.0
<PackageReference Include="ThrowIfArgument" Version="2.0.0" />
<PackageVersion Include="ThrowIfArgument" Version="2.0.0" />
<PackageReference Include="ThrowIfArgument" />
paket add ThrowIfArgument --version 2.0.0
#r "nuget: ThrowIfArgument, 2.0.0"
#:package ThrowIfArgument@2.0.0
#addin nuget:?package=ThrowIfArgument&version=2.0.0
#tool nuget:?package=ThrowIfArgument&version=2.0.0
ThrowIfArgument
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
Supported frameworks
- .NET 8
- .NET 10
Versions 1.x of the package also support .NET 6 and .NET 7.
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 class ThrowIfArgumentExtensions
{
public static string StartsWithThunderclap
(
this IThrowIfBuilder builder,
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 | Versions 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. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.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 |
|---|---|---|
| 2.0.0 | 794 | 10/13/2026 |
| 1.1.0 | 30,833 | 5/29/2024 |
| 1.0.3 | 16,694 | 12/9/2022 |
| 1.0.2 | 1,135 | 12/7/2022 |
| 1.0.1 | 531 | 12/7/2022 |
| 1.0.0 | 548 | 12/6/2022 |
| 0.0.0-alpha04 | 326 | 12/6/2022 |
| 0.0.0-alpha03 | 373 | 12/2/2022 |
| 0.0.0-alpha02 | 332 | 12/2/2022 |
| 0.0.0-alpha01 | 379 | 12/2/2022 |
Support .NET 10; drop end-of-life .NET 6 and .NET 7 targets