https://github.com/benfoster/o9d-guard
Opinionated Guard Extensions for .NET
https://github.com/benfoster/o9d-guard
Last synced: 14 days ago
JSON representation
Opinionated Guard Extensions for .NET
- Host: GitHub
- URL: https://github.com/benfoster/o9d-guard
- Owner: benfoster
- License: mit
- Created: 2021-02-13T07:09:08.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-16T13:12:09.000Z (over 3 years ago)
- Last Synced: 2025-04-10T10:13:46.858Z (17 days ago)
- Language: C#
- Homepage: https://benfoster.github.io/o9d-guard/
- Size: 514 KB
- Stars: 13
- Watchers: 4
- Forks: 2
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Guard
[](https://www.nuget.org/packages/O9d.Guard)
[](https://www.nuget.org/packages/O9d.Guard)
[](https://benfoster.mit-license.org/)
[](https://coveralls.io/github/benfoster/o9d-guard?branch=main)
[](https://sonarcloud.io/dashboard?id=benfoster_o9d-guard)
[](https://dashboard.guardrails.io/gh/benfoster/65586)
[](https://codescene.io/projects/12974)Guard is an o[pinionate]d guard/assertions library for .NET that simplifies argument checking.
**Without Guard:**
```c#
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:**
```c#
public Customer(string name, PhoneNumber phone)
{
Name = name.NotNullOrWhiteSpace(nameof(name));
Phone = phone.NotNull(nameof(phone));
}
```## Quick Start
Add the O9d.Guard package from [NuGet](https://www.nuget.org/packages/O9d.Guard)
```
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
Pre-release packages can be downloaded from [GitHub Packages](https://github.com/benfoster?tab=packages&repo_name=o9d-guard).
```
dotnet add package O9d.Guard --prerelease --source https://nuget.pkg.github.com/benfoster/index.json
```[More information](https://docs.github.com/en/packages/guides/configuring-dotnet-cli-for-use-with-github-packages) on using GitHub packages with .NET.
## Building locally
This project uses [Cake](https://cakebuild.net/) 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.
## Contributing
To contribute to O9d.Guard, fork the repository and raise a PR. If your change is substantial please [open an issue](https://github.com/benfoster/o9d-guard/issues) first to discuss your objective.
## Docs
The Guard documentation is built using [DocFx](https://dotnet.github.io/docfx/). To build and serve the docs locally run:
```
./build.sh --target ServeDocs
```This will serve the docs on http://localhost:8080.