Singulink.Enums 2.3.1

Prefix Reserved
dotnet add package Singulink.Enums --version 2.3.1
                    
NuGet\Install-Package Singulink.Enums -Version 2.3.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="Singulink.Enums" Version="2.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Singulink.Enums" Version="2.3.1" />
                    
Directory.Packages.props
<PackageReference Include="Singulink.Enums" />
                    
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 Singulink.Enums --version 2.3.1
                    
#r "nuget: Singulink.Enums, 2.3.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.
#:package Singulink.Enums@2.3.1
                    
#: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=Singulink.Enums&version=2.3.1
                    
Install as a Cake Addin
#tool nuget:?package=Singulink.Enums&version=2.3.1
                    
Install as a Cake Tool

Chat on Discord View nuget packages Build and Test

Singulink Enums is a tiny (~30KB), highly optimized library with full AOT support that provides generic operations and extension methods for enumeration types. It contains a comprehensive set of the most common enumeration "must haves" that are missing from the .NET runtime. The effect on runtime memory footprint has been pushed to the bare minimum while still supporting common scenarios in the most efficient way possible.

We are a small team of engineers and designers dedicated to building beautiful, functional and well-engineered software solutions. We offer very competitive rates as well as fixed-price contracts and welcome inquiries to discuss any custom development / project support needs you may have.

This package is part of our Singulink Libraries collection. Visit https://github.com/Singulink to see our full list of publicly available libraries and other open-source projects.

Installation

The package is available on NuGet - simply install the Singulink.Enums package.

Supported Runtimes: Everywhere .NET Standard 2.0 is supported, including:

  • .NET
  • .NET Framework
  • Mono / Xamarin

API

You can view the fully documented API on the project documentation site.

The main classes of interest are:

  1. Enum<T> - Static generic helper properties and methods when the enum type needs to specified, i.e. for parsing.
  2. EnumExtensions - Extension methods to validate enums and perform operations on values.
  3. EnumConverter<T> - Enum converter that can convert enums to and from strings. Separators, enum names and case-sensitivity are fully customizable.

Usage

The API is fairly self-explanatory and well documented but here are some examples to show what the library offers:

using Singulink.Enums;

// Get enum names
var enumNames = Enum<ConsoleKey>.Names;

// Get enum values
var enumValues = Enum<ConsoleKey>.Values;

// Get enum field name for a particular value
string backspaceName = ConsoleKey.Backspace.GetName();

// Parse using the default converter
ConsoleKey backspace = Enum<ConsoleKey>.Parse("Backspace");

// Bitwise flag operations
var value = AttributeTargets.Assembly;
value = value.SetFlags(AttributeTargets.Class, AttributeTargets.Method); // set additional flags
bool hasClassAndMethod = value.HasAllFlags(AttributeTargets.Class, AttributeTargets.Method); // true
bool hasClassOrStruct = value.HasAnyFlag(AttributeTargets.Class, AttributeTargets.Struct); // true
IReadOnlyList<AttributeTargets> splitValues = value.SplitFlags(); // 3 separate flags split out

// Create a case-insensitive converter with a non-default separator
var converter = new EnumConverter<AttributeTargets>(opt => {
    opt.Separator = " | ";
    opt.IgnoreCase = true;
});

// Convert enum value to/from string using the customized converter
string enumString = converter.AsString(value) // "Assembly | Class | Method"
value = converter.Parse(enumString.ToLowerInvariant()); // Assembly, Class and Method flags set

// Create an enum converter that uses the [Display] attribute to get the names
var displayNameConverter = new EnumConverter<YourEnum>(opt => opt.WithDisplayNameGetter());

public void Method(AttributeTargets targets)
{
    // Throw ArgumentOutOfRangeException if targets is not a valid flag combo
    targets.ThrowIfNotValid(nameof(targets));
}

public void Method(ConsoleKey key)
{
    // Throw ArgumentOutOfRangeException if key is not defined
    key.ThrowIfNotDefined(nameof(key));
}

Benchmarks (.NET 8.0)

The following is a comparison between Singulink Enums, Enums.Net (v5.0) and operators / system methods (where applicable):

| Method                            | Mean        | Error     | StdDev    |
|---------------------------------- |-------------|-----------|-----------|
| AreFlagsDefined_Singulink         |   0.0195 ns | 0.0001 ns | 0.0001 ns |
| AreFlagsDefined_EnumsNet          |   0.0225 ns | 0.0002 ns | 0.0002 ns |
|                                   |             |           |           |
| ClearFlags_Singulink              |   0.0118 ns | 0.0001 ns | 0.0001 ns |
| ClearFlags_EnumsNet               |   0.2314 ns | 0.0005 ns | 0.0004 ns |
| ClearFlags_Operator               |   0.0117 ns | 0.0002 ns | 0.0001 ns |
|                                   |             |           |           |
| HasAllFlags_Singulink             |   0.0196 ns | 0.0003 ns | 0.0003 ns |
| HasAllFlags_EnumsNet              |   0.3364 ns | 0.0005 ns | 0.0005 ns |
| HasAllFlags_System                |   0.0120 ns | 0.0002 ns | 0.0002 ns |
|                                   |             |           |           |
| HasAnyFlags_Singulink             |   0.0191 ns | 0.0002 ns | 0.0001 ns |
| HasAnyFlags_EnumsNet              |   0.2738 ns | 0.0004 ns | 0.0003 ns |
| HasAnyFlags_Operator              |   0.0123 ns | 0.0002 ns | 0.0002 ns |
|                                   |             |           |           |
| IsDefined_Singulink               |   0.3984 ns | 0.0008 ns | 0.0008 ns |
| IsDefined_EnumsNet                |   1.3387 ns | 0.0026 ns | 0.0024 ns |
| IsDefined_System                  |   2.0957 ns | 0.0064 ns | 0.0060 ns |
|                                   |             |           |           |
| ParseMultiple_Singulink           |  33.5060 ns | 0.1024 ns | 0.0958 ns |
| ParseMultiple_EnumsNet            |  51.4606 ns | 0.0518 ns | 0.0484 ns |
| ParseMultiple_System              |  51.4423 ns | 0.1366 ns | 0.1278 ns |
|                                   |             |           |           |
| ParseMultipleIgnoreCase_Singulink |  33.6575 ns | 0.0168 ns | 0.0157 ns |
| ParseMultipleIgnoreCase_EnumsNet  |  56.0421 ns | 0.1147 ns | 0.1073 ns |
| ParseMultipleIgnoreCase_System    |  50.4676 ns | 0.1079 ns | 0.1009 ns |
|                                   |             |           |           |
| ParseSingle_Singulink             |   7.5045 ns | 0.0265 ns | 0.0248 ns |
| ParseSingle_EnumsNet              |  15.5357 ns | 0.0273 ns | 0.0255 ns |
| ParseSingle_System                |  37.5409 ns | 0.1051 ns | 0.0932 ns |
|                                   |             |           |           |
| ParseSingleIgnoreCase_Singulink   |   7.4814 ns | 0.0347 ns | 0.0325 ns |
| ParseSingleIgnoreCase_EnumsNet    |  16.7586 ns | 0.0220 ns | 0.0206 ns |
| ParseSingleIgnoreCase_System      |  39.3521 ns | 0.0308 ns | 0.0273 ns |
|                                   |             |           |           |
| SetFlags_Singulink                |   0.0124 ns | 0.0003 ns | 0.0002 ns |
| SetFlags_EnumsNet                 |   0.2272 ns | 0.0001 ns | 0.0001 ns |
| SetFlags_Operator                 |   0.0121 ns | 0.0002 ns | 0.0002 ns |
|                                   |             |           |           |
| SplitFlags_Singulink*             |  23.2878 ns | 0.0286 ns | 0.0254 ns |
| SplitFlags_EnumsNet               |  84.8990 ns | 0.1504 ns | 0.1407 ns |
|                                   |             |           |           |
| AsStringMultiple_Singulink*       |  77.5238 ns | 0.1581 ns | 0.1402 ns |
| AsStringMultiple_EnumsNet         | 147.6367 ns | 0.4769 ns | 0.4461 ns |
| AsStringMultiple_System           |  47.0363 ns | 0.6862 ns | 0.6083 ns |
|                                   |             |           |           |
| AsStringSingle_Singulink          |   5.1679 ns | 0.0093 ns | 0.0082 ns |
| AsStringSingle_EnumsNet           |   4.0529 ns | 0.0087 ns | 0.0082 ns |
| AsStringSingle_System             |   5.6126 ns | 0.0113 ns | 0.0105 ns |
|---------------------------------- |-------------|-----------|-----------|

* Split flags and flags converted to strings are returned in descending order based on the highest bits set first (with any remainder added to the end). This behavior differs from Enums.Net and system methods as this is usually what developers want. You also have the option to return all matching flags or just the minimal set of flags that can be combined to form the original value (see SplitFlagsOptions).

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 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.  net8.0-windows10.0.19041 is compatible.  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. 
.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 (8)

Showing the top 5 NuGet packages that depend on Singulink.Enums:

Package Downloads
Singulink.Numerics.BigIntegerExtensions

Extensions and helpers for BigInteger, including a cache that stores powers of numbers so they don't have to be computed each time.

Singulink.Numerics.BigDecimal

Fully-featured support for arbitrarily large precision decimal values.

Singulink.IO.FileSystem

Reliable cross-platform strongly-typed file/directory path manipulation and file system access.

Singulink.Net.FileHosting

Library that facilitates file and image storage for hosting purposes.

Singulink.UI.Navigation

Strongly-typed AOT-friendly navigation framework with comprehensive deep-linking support.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.1 3,839 7/26/2025
2.3.0 564 7/13/2025
2.2.0 334 7/7/2025
2.1.1 545 10/24/2024
2.0.3 136 10/23/2024
2.0.2 131 10/22/2024
2.0.1 128 10/22/2024
1.2.1 585 2/10/2021
1.2.0 484 1/7/2021
1.1.0 565 10/24/2020
1.0.0 515 10/16/2020