ThrowIfArgument 1.1.0
dotnet add package ThrowIfArgument --version 1.1.0
NuGet\Install-Package ThrowIfArgument -Version 1.1.0
<PackageReference Include="ThrowIfArgument" Version="1.1.0" />
paket add ThrowIfArgument --version 1.1.0
#r "nuget: ThrowIfArgument, 1.1.0"
// 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
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 | Versions 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. |
-
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 | 1,463 | 5/29/2024 |
1.0.3 | 16,182 | 12/9/2022 |
1.0.2 | 866 | 12/7/2022 |
1.0.1 | 311 | 12/7/2022 |
1.0.0 | 313 | 12/6/2022 |
0.0.0-alpha04 | 110 | 12/6/2022 |
0.0.0-alpha03 | 150 | 12/2/2022 |
0.0.0-alpha02 | 116 | 12/2/2022 |
0.0.0-alpha01 | 155 | 12/2/2022 |
Support .NET 8