Heleonix.Guard 2.0.1

dotnet add package Heleonix.Guard --version 2.0.1
NuGet\Install-Package Heleonix.Guard -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Heleonix.Guard" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Heleonix.Guard --version 2.0.1
#r "nuget: Heleonix.Guard, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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


Release: .NET / NuGet

Provides performant guard functionality for methods to throw exceptions




See Heleonix.Guard


using Heleonix.Guard;
using Heleonix.Extensions;
using static Heleonix.Guard.Host;

public static class Test
    public static void Main()

    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

  1. Create a fork from the main repository

  2. Implement whatever is needed

  3. Create a Pull Request. Make sure the assigned Checks pass successfully.

  4. Request review from the code owner

  5. Once approved, merge your Pull Request via Squash and merge

    While merging, enter a Conventional Commits commit message. This commit message will be used in automatically generated Github Release Notes and NuGet Release Notes

  6. Monitor the Release: .NET / NuGet GitHub workflow to make sure your changes are delivered successfully

  7. In case of any issues, please contact heleonix.sln@gmail.com

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
2.0.1 88 3/30/2024
2.0.0 386 10/7/2022
1.0.0 2,917 6/22/2018

"2.0.1 (3/30/2024)

Bug Fixes
- Added documentation as a website."