PineGuard.GuardClauses
0.1.0-alpha.7
dotnet add package PineGuard.GuardClauses --version 0.1.0-alpha.7
NuGet\Install-Package PineGuard.GuardClauses -Version 0.1.0-alpha.7
<PackageReference Include="PineGuard.GuardClauses" Version="0.1.0-alpha.7" />
<PackageVersion Include="PineGuard.GuardClauses" Version="0.1.0-alpha.7" />
<PackageReference Include="PineGuard.GuardClauses" />
paket add PineGuard.GuardClauses --version 0.1.0-alpha.7
#r "nuget: PineGuard.GuardClauses, 0.1.0-alpha.7"
#:package PineGuard.GuardClauses@0.1.0-alpha.7
#addin nuget:?package=PineGuard.GuardClauses&version=0.1.0-alpha.7&prerelease
#tool nuget:?package=PineGuard.GuardClauses&version=0.1.0-alpha.7&prerelease
PineGuard.GuardClauses
Stop bad input at the door. Keep the parsed value. Throw your exceptions, not ArgumentException.
Guard.Against.NotHttpsUrl(url) takes a string and hands back a Uri. If the input wasn't a valid HTTPS URL, it throws — if it was, you get the parsed value with no second new Uri(...) call. Every guard in PineGuard works this way: bad input stops at the boundary, and the parsed, typed value flows on.
Guards fit anywhere invalid input should stop execution immediately — constructors, factory methods, service methods, API layer boundaries, and parameter checks on any public method. They're a perfect fit for Domain-Driven Design, where the always-valid-state principle means entities, value objects, and aggregates can't exist in an invalid state. Guards enforce that invariant right in the constructor, so bad data never crosses into your domain.
Where PineGuard goes further than any other guard library: your exception, not ArgumentException. Replace the default globally, per-scope, or per-call — so new Order(...) throws InvalidOrderException and new Checkout(...) throws CheckoutException. Other libraries stop at a per-call override; PineGuard's scoped and global policies let your whole domain speak one exception vocabulary without each call site opting in.
Install
dotnet add package PineGuard.GuardClauses
Targets net8.0, net10.0, and netstandard2.1. Depends on PineGuard.Core and PineGuard.MustClauses.
Examples
using PineGuard.GuardClauses;
// The four canonical rules — each throws on failure, returns the parsed value on success
string email = Guard.Against.NotEmail(userEmail);
string strictEmail = Guard.Against.NotStrictEmail(userEmail);
string safe = Guard.Against.OwaspUnsafe(userInput);
Uri callbackUri = Guard.Against.NotHttpsUrl(callback); // returns Uri, not string
// Compose at a service boundary
public EndpointConfiguration Create(string callback, string userEmail, string userInput)
{
return new EndpointConfiguration(
Guard.Against.NotHttpsUrl(callback),
Guard.Against.NotEmail(userEmail),
Guard.Against.OwaspUnsafe(userInput));
}
Your domain, your exception story
// Replace globally
GuardExceptionPolicy.ExceptionReplacer = ex => new DomainValidationException(ex.Message, ex);
GuardExceptionPolicy.ReplaceDefaultExceptions = true;
// Or just for a block
using (GuardExceptionPolicy.BeginScope(o =>
o.ExceptionReplacer = ex => new CheckoutException(ex.Message, ex)))
{
Guard.Against.NotNull(orderId);
}
// Or just for one call
Guard.Against.NotNull(orderId,
exceptionCreator: () => new CheckoutException("Order id is required."));
Other layers, same rule library
- Caller should decide what to do on failure → PineGuard.MustClauses
- Pipeline-style request validation → PineGuard.FluentValidation
- Attribute-driven models → PineGuard.DataAnnotations
See the full documentation for the complete Guard.Against.* catalog and exception-policy options.
License
MIT © Steve McCormack
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- PineGuard.Core (>= 0.1.0-alpha.7)
- PineGuard.MustClauses (>= 0.1.0-alpha.7)
-
net10.0
- PineGuard.Core (>= 0.1.0-alpha.7)
- PineGuard.MustClauses (>= 0.1.0-alpha.7)
-
net8.0
- PineGuard.Core (>= 0.1.0-alpha.7)
- PineGuard.MustClauses (>= 0.1.0-alpha.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-alpha.7 | 193 | 4/20/2026 |
| 0.1.0-alpha.6 | 66 | 4/20/2026 |
| 0.1.0-alpha.5 | 65 | 4/18/2026 |