Heleonix.Guard
2.0.1
dotnet add package Heleonix.Guard --version 2.0.1
NuGet\Install-Package Heleonix.Guard -Version 2.0.1
<PackageReference Include="Heleonix.Guard" Version="2.0.1" />
paket add Heleonix.Guard --version 2.0.1
#r "nuget: Heleonix.Guard, 2.0.1"
// Install Heleonix.Guard as a Cake Addin #addin nuget:?package=Heleonix.Guard&version=2.0.1 // Install Heleonix.Guard as a Cake Tool #tool nuget:?package=Heleonix.Guard&version=2.0.1
Heleonix.Guard
Provides performant guard functionality for methods to throw exceptions
Install
https://www.nuget.org/packages/Heleonix.Guard
Documentation
See Heleonix.Guard
Example
using Heleonix.Guard;
using Heleonix.Extensions;
using static Heleonix.Guard.Host;
public static class Test
{
public static void Main()
{
MyMethod(null);
}
public static void MyMethod(string param)
{
// C# 7.2+: Non-Trailing named arguments
Throw.ArgumentNullException(when: param.IsNull(), nameof(param));
// OR
// Prior to C# 7.2: You can use a helper method 'When'
Throw.ArgumentNullException(When(param.IsNull()), nameof(param));
// OR
Throw.ArgumentNullException(param == null, nameof(param));
// OR
Throw.ArgumentNullException(When(param == null), nameof(param));
}
}
The Heleonix.Extensions
provides many useful predicative extensions to build assertions,
like IsNull()
, IsNullOrEmptyOrWhiteSpace()
, IsLessThan()
etc.
These extensions do not throw exceptions, so they will not overlap an exception to be really thrown. See Heleonix.Extensions for more details.
The Host.Throw
property returns a singleton instance of the Heleonix.Guard.ExceptionRaiser
class,
which provides methods to throw many existing exceptions, like ArgumentNullException
, FileLoadException
etc.
See more via VisualStudio intellisense.
The ExceptionRaiser
returned by the Host.Throw
is the singleton instance, so there is no creations of new objects every time,
as it is usually implemented in fluent interfaces. Besides, it also provides ability to implement custom exception raisers via extension methods:
using Heleonix.Guard;
public static class ExceptionRaiserExtensions
{
#pragma warning disable CC0057 // Unused parameters
public static void MyCustomException(this ExceptionRaiser raiser, bool when, int param1, string param2, object paramN, string message = null, Exception innerException = null)
{
if (when)
{
throw new MyCustomException(param1, param2, paramN, message, innerException);
}
}
#pragma warning restore CC0057 // Unused parameters
}
and then use it, for example, as below:
Throw.MyCustomException(when: param1.IsZero() || param2.IsNullOrEmpty() || paramN.IsNull(), "some message");
Contribution Guideline
Create a fork from the main repository
Implement whatever is needed
Create a Pull Request. Make sure the assigned Checks pass successfully.
Request review from the code owner
Once approved, merge your Pull Request via Squash and merge
IMPORTANT
While merging, enter a Conventional Commits commit message. This commit message will be used in automatically generated Github Release Notes and NuGet Release NotesMonitor the Release: .NET / NuGet GitHub workflow to make sure your changes are delivered successfully
In case of any issues, please contact heleonix.sln@gmail.com
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 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
"2.0.1 (3/30/2024)
Bug Fixes
- Added documentation as a website."