Ardalis.SmartEnum.GuardClauses 9.0.0

dotnet add package Ardalis.SmartEnum.GuardClauses --version 9.0.0
                    
NuGet\Install-Package Ardalis.SmartEnum.GuardClauses -Version 9.0.0
                    
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="Ardalis.SmartEnum.GuardClauses" Version="9.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ardalis.SmartEnum.GuardClauses" Version="9.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Ardalis.SmartEnum.GuardClauses" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ardalis.SmartEnum.GuardClauses --version 9.0.0
                    
#r "nuget: Ardalis.SmartEnum.GuardClauses, 9.0.0"
                    
#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.
#:package Ardalis.SmartEnum.GuardClauses@9.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ardalis.SmartEnum.GuardClauses&version=9.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Ardalis.SmartEnum.GuardClauses&version=9.0.0
                    
Install as a Cake Tool

Ardalis.SmartEnum.GuardClauses

IMPORTANT This is the last MIT-licensed release of this library. Future releases will require a (potentially free) commercial license. Find out more

Ardalis.GuardClauses support for Ardalis.SmartEnum. Adds a SmartEnumOutOfRange guard that returns the matching SmartEnum instance for a value, or throws if there isn't one.

Installation

dotnet add package Ardalis.SmartEnum.GuardClauses

Usage

Pass the value to Guard.Against.SmartEnumOutOfRange. It returns the matching instance, or throws a SmartEnumNotFoundException:

using Ardalis.GuardClauses;
using Ardalis.SmartEnum;
using Ardalis.SmartEnum.GuardClauses;

public class Status : SmartEnum<Status>
{
    public static readonly Status Draft = new Status(nameof(Draft), 1);
    public static readonly Status Published = new Status(nameof(Published), 2);

    private Status(string name, int value) : base(name, value) { }
}

public void UpdateStatus(int statusValue)
{
    Status status = Guard.Against.SmartEnumOutOfRange<Status>(statusValue);
    // use status here
}

For a SmartEnum whose value type isn't int, pass both type arguments:

Color color = Guard.Against.SmartEnumOutOfRange<Color, string>(colorValue);

You can also pass a custom message, or an exceptionCreator to throw your own exception type:

var status = Guard.Against.SmartEnumOutOfRange<Status>(statusValue,
    exceptionCreator: () => new ArgumentException("Invalid status."));

More information

See the SmartEnum project README for full documentation.

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.  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.  net11.0 is compatible. 
.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.

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
9.0.0 95 11/24/2026
8.1.0 21,073 10/3/2024
8.0.0 270 10/3/2024

See root package release notes