Enumem 1.0.5

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

Enumem

NuGet Version NuGet Downloads

Enumem is a lightweight .NET library that provides safe and convenient extensions for working with enums.

It simplifies parsing, retrieving descriptions, listing values, and converting enums into dictionaries, making enum handling more expressive and reliable.


Installation

Install the package from NuGet:

dotnet add package Enumem

Basic Usage


UserRole.cs:

using System.ComponentModel;
using Enumem;

public enum UserRole
{
    [Description("System Administrator")]
    Admin = 1,

    [Description("Regular User")]
    User = 2,

    [Description("Guest Account")]
    Guest = 3
}


GetValue

  • Retrieves the numeric (underlying) value of an enum member.
  • Useful when you need the integer representation.

var numericValue = UserRole.User.GetValue();
var numericValue2 = Enumem.GetValue(UserRole.User);

Console.WriteLine($"numericValue --> {numericValue}");
Console.WriteLine($"numericValue2 --> {numericValue2}");

numericValue --> 2
numericValue2 --> 2


GetValues

  • Returns a list of all enum values defined in the type.
  • Ideal for iteration or populating dropdowns.

var values = Enumem.GetValues<UserRole>().ToList();
Console.WriteLine($"values --> {string.Join(", ", values)}");

values --> [Admin, User, Guest]


GetAllNames

  • Returns all enum member names as strings.
  • Helpful for reflection or dynamic mapping.

var names = Enumem.GetAllNames<UserRole>().ToList();

Console.WriteLine($"names --> {string.Join(", ", names)}");
names --> ["Admin", "User", "Guest"]


GetDescription

  • Retrieves the human-readable description assigned to an enum value.
  • Useful for displaying friendly names in UI or logs.

var description = UserRole.Admin.GetDescription();
var description2 = Enumem.GetDescription(UserRole.Admin);

Console.WriteLine($"description --> {description}");
Console.WriteLine($"description2 --> {description2}");

"description --> System Administrator"
"description2 --> System Administrator"


GetAllDescriptions

  • Returns all description attributes defined for the enum members.
  • Useful for displaying descriptive labels in UI components.

var descriptions = Enumem.GetAllDescriptions<UserRole>().ToList();

Console.WriteLine($"descriptions --> {string.Join(", ", descriptions)}");
descriptions --> ["System Administrator", "Regular User", "Guest Account"]


GetEnumFromDescription

Converts a description string back into its corresponding enum value. Useful when mapping user-facing labels to internal enum values.


var roleFromDesc = Enumem.GetEnumFromDescription<UserRole>("Regular User");

Console.WriteLine($"roleFromDesc --> {roleFromDesc}");
roleFromDesc --> User


ToDictionary

  • Builds a dictionary mapping each enum’s numeric value to its description.
  • Perfect for quick lookups or serialization.

var dict = Enumem.ToDictionary<UserRole>();
Console.WriteLine($"dict --> {string.Join(", ", dict)}");
dict --> [ 1, "System Administrator"], [ 2, "Regular User" ], [ 3, "Guest Account" ]

var dict2 = Enumem.ToDictionary<UserRole>();
foreach (var kvp in dict2)
    Console.WriteLine($"{kvp.Key}: {kvp.Value}");
	
//1: System Administrator
//2: Regular User
//3: Guest Account


IsDefined

  • Checks whether a given string matches a valid enum name.
  • Prevents invalid conversions or runtime errors.

var isDefined = Enumem.IsDefined<UserRole>("Admin");

Console.WriteLine($"isDefined --> {isDefined}");
isDefined --> true


TryParseEnum

  • Safely attempts to convert a string into its corresponding enum value.
  • Returns true if the conversion succeeds, false otherwise.

var success = Enumem.TryParseEnum("Admin", out UserRole role1);
Console.WriteLine($"Success --> {success}");
Success --> true


✨ Features

  • Safe parsing of enums with TryParseEnum
  • Retrieve enum descriptions via [Description] attribute
  • List all enum values and names easily
  • Convert enums into dictionaries (numeric value → description)
  • Check if a name is defined in the enum
  • Reverse lookup: get enum from its description

Support the Project

If you find this library useful, consider supporting its development:

Buy Me a Coffee


⚖️ License

This project is freely available under the MIT license.
You may use it without restrictions, as long as you retain the reference to the original license.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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
1.0.5 138 6/14/2026
1.0.4 110 5/22/2026
1.0.3 110 5/15/2026
1.0.2 110 5/15/2026
1.0.1 102 5/15/2026
1.0.0 107 5/15/2026