Soenneker.Gen.EnumValues 4.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Gen.EnumValues --version 4.0.2
                    
NuGet\Install-Package Soenneker.Gen.EnumValues -Version 4.0.2
                    
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="Soenneker.Gen.EnumValues" Version="4.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Gen.EnumValues" Version="4.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Gen.EnumValues" />
                    
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 Soenneker.Gen.EnumValues --version 4.0.2
                    
#r "nuget: Soenneker.Gen.EnumValues, 4.0.2"
                    
#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 Soenneker.Gen.EnumValues@4.0.2
                    
#: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=Soenneker.Gen.EnumValues&version=4.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Gen.EnumValues&version=4.0.2
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Gen.EnumValues

Compile-time generated enum values. Zero reflection. Zero allocations.

Generate value objects with fast lookup APIs, switch-friendly constants, and built-in JSON serialization (System.Text.Json/Newtonsoft.Json).

Installation

dotnet add package Soenneker.Gen.EnumValues

Usage

Annotate a partial type with [EnumValue] (defaults to int) or [EnumValue<T>]:

using Soenneker.Gen.EnumValues;

[EnumValue]
public sealed partial class OrderStatus
{
    public static readonly OrderStatus Pending = new(1);
    public static readonly OrderStatus Completed = new(2);
}
using Soenneker.Gen.EnumValues;

[EnumValue<string>]
public sealed partial class ColorCode
{
    public static readonly ColorCode Red = new("R");
    public static readonly ColorCode Blue = new("B");
}

The generator emits:

  • List
  • <MemberName>Value constants (for constant-friendly switch labels)
  • TryFromValue(TValue value, out TEnum result)
  • FromValue(TValue value)
  • TryFromName(string name, out TEnum result)
  • FromName(string name)

Lookups

if (OrderStatus.TryFromValue(1, out var pending))
{
    // pending == OrderStatus.Pending
}

var completed = OrderStatus.FromValue(2);

if (ColorCode.TryFromName("Red", out var red))
{
    // red == ColorCode.Red
}

Switching over values

Switch labels must be compile-time constants. The generator emits <MemberName>Value constants so you can switch efficiently on Value:

switch (orderStatus.Value)
{
    case OrderStatus.PendingValue:
        // ...
        break;
    case OrderStatus.CompletedValue:
        // ...
        break;
}

If your variable is already the raw value type (int, string, etc.), you can switch directly on that variable with the same constants.

Serialization

System.Text.Json is always supported and the converter is applied automatically.

Newtonsoft.Json is also supported automatically when your project references Newtonsoft.Json:

dotnet add package Newtonsoft.Json

After that, both serializers round-trip by Value.

Value and the value constructor are generated automatically if they do not already exist.

Notes

  • The enum type must be partial.
  • Top-level non-generic class/struct types are supported.
  • Static instances must be initialized with a compile-time constant first constructor argument.
  • <MemberName>Value constants are emitted for const-compatible value types (for example: numeric types, string, char, bool).
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (49)

Showing the top 5 NuGet packages that depend on Soenneker.Gen.EnumValues:

Package Downloads
Soenneker.Enums.JsonOptions

An enumeration for common JSON options

Soenneker.Enums.JsonLibrary

An enumeration for common JSON library types

Soenneker.Enums.DeployEnvironment

An enum for standard deployment environments

Soenneker.Enums.UnitOfTime

An enumerator for describing an interval of time

Soenneker.Blazor.TomSelect

A Blazor interop library for the select user control library, Tom Select

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.30 53 3/12/2026
4.0.29 140 3/12/2026
4.0.27 180 3/12/2026
4.0.26 2,340 3/12/2026
4.0.25 35,347 3/11/2026
4.0.24 3,627 3/10/2026
4.0.23 37,808 3/9/2026
4.0.22 782 3/9/2026
4.0.21 528 3/9/2026
4.0.20 92,861 3/6/2026
4.0.19 29,570 3/4/2026
4.0.18 6,678 3/4/2026
4.0.17 35,144 3/4/2026
4.0.15 51,079 3/3/2026
4.0.14 35,243 2/27/2026
4.0.13 2,142 2/27/2026
4.0.12 101 2/27/2026
4.0.11 19,721 2/27/2026
4.0.10 5,724 2/27/2026
4.0.2 140 2/25/2026
Loading failed