Opinionated Guard Extensions for .NET
MIT License
Guard is an o[pinionate]d guard/assertions library for .NET that simplifies argument checking.
Without Guard:
public Customer(string name, PhoneNumber phone)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("Name must be provided required", nameof(name));
}
Name = name;
Phone = phone ?? throw new ArgumentNullException(nameof(phone));
}
With Guard:
public Customer(string name, PhoneNumber phone)
{
Name = name.NotNullOrWhiteSpace(nameof(name));
Phone = phone.NotNull(nameof(phone));
}
Add the O9d.Guard package from NuGet
dotnet add package O9d.Guard
If you want to use a pre-release package, you can download them GitHub packages.
Import the O9d.Guard
namespace and start using the extension to validate arguments.
Pre-release packages can be downloaded from GitHub Packages.
dotnet add package O9d.Guard --prerelease --source https://nuget.pkg.github.com/benfoster/index.json
More information on using GitHub packages with .NET.
This project uses Cake to build, test and publish packages.
Run build.sh
(Mac/Linux) or build.ps1
(Windows) To build and test the project.
This will output NuGet packages and coverage reports in the artifacts
directory.
To contribute to O9d.Guard, fork the repository and raise a PR. If your change is substantial please open an issue first to discuss your objective.
The Guard documentation is built using DocFx. To build and serve the docs locally run:
./build.sh --target ServeDocs
This will serve the docs on http://localhost:8080.