Soenneker.Gen.EnumValues
4.0.2
Prefix Reserved
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
<PackageReference Include="Soenneker.Gen.EnumValues" Version="4.0.2" />
<PackageVersion Include="Soenneker.Gen.EnumValues" Version="4.0.2" />
<PackageReference Include="Soenneker.Gen.EnumValues" />
paket add Soenneker.Gen.EnumValues --version 4.0.2
#r "nuget: Soenneker.Gen.EnumValues, 4.0.2"
#:package Soenneker.Gen.EnumValues@4.0.2
#addin nuget:?package=Soenneker.Gen.EnumValues&version=4.0.2
#tool nuget:?package=Soenneker.Gen.EnumValues&version=4.0.2
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>Valueconstants (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>Valueconstants are emitted for const-compatible value types (for example: numeric types,string,char,bool).
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 |