Guard.Net
2.0.0
See the version list below for details.
dotnet add package Guard.Net --version 2.0.0
NuGet\Install-Package Guard.Net -Version 2.0.0
<PackageReference Include="Guard.Net" Version="2.0.0" />
<PackageVersion Include="Guard.Net" Version="2.0.0" />
<PackageReference Include="Guard.Net" />
paket add Guard.Net --version 2.0.0
#r "nuget: Guard.Net, 2.0.0"
#:package Guard.Net@2.0.0
#addin nuget:?package=Guard.Net&version=2.0.0
#tool nuget:?package=Guard.Net&version=2.0.0
Guard.NET
A simple library that facilitates runtime checks of code and allows to define preconditions and invariants within a method.
Its main purpose is to leverage the precondition checks that appear in almost all methods, through a clean interface that accentuates intention and eliminates confusion.
Usage
public void AddUser(User user)
{
Guard.NotNull(user, nameof(user), "optional custom error message"); // throws ArgumentNullException
// OR use an explicit Exception
var invalidOperationException = new InvalidOperationException("custom message");
Guard.NotNull(user, invalidOperationException);
...
}
public void GetUserByName(string name)
{
Guard.NotNullOrWhitespace(name, nameof(name), "optional custom error message"); // throws ArgumentException
// OR use an explicit Exception
var invalidOperationException = new InvalidOperationException("custom message");
Guard.NotNullOrWhitespace(userName, invalidOperationException);
...
}
public void GetUsers(int pageSize)
{
Guard.NotGreaterThan(pageSize, _maxPageSize, nameof(pageSize), "optional custom error message"); // throws ArgumentOutOfRangeException
// OR use an explicit Exception
var invalidOperationException = new InvalidOperationException("custom message");
Guard.NotGreaterThan(pageSize, _maxPageSize, invalidOperationException);
...
}
public void UpdateEmailAddress(int userId, string newEmailAddress)
{
Guard.For(() => userId < 0, new ArgumentException(nameof(userId)));
Guard.For(() => Regex.IsMatch(newEmailAddress, _emailRegexPattern), new ArgumentException(nameof(newEmailAddress)));
...
}
Installation
The Guard class can be used by installing Guard.NET nuget package available here.
Install-Package Guard.NET
The package has no external dependencies.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. 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 was computed. 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 was computed. 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. |
-
net5.0
- No dependencies.
NuGet packages (26)
Showing the top 5 NuGet packages that depend on Guard.Net:
| Package | Downloads |
|---|---|
|
Arcus.Security.Core
Contains core functionality for Arcus.Security |
|
|
Arcus.EventGrid
Provides core capabilities for using Event Grid with Arcus |
|
|
Arcus.EventGrid.Publishing
Provides capability to push events to Azure Event Grid |
|
|
Arcus.EventGrid.Testing
Provides infrastructure to build automated testing with Azure Event Grid. |
|
|
Arcus.Security.Secrets.Core
Contains core functionality for working with secrets |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Guard.Net:
| Repository | Stars |
|---|---|
|
tomkerkhove/promitor
Bringing Azure Monitor metrics where you need them.
|
Migrated to .NET 5