UtilityVerse.Enum
0.1.0
dotnet add package UtilityVerse.Enum --version 0.1.0
NuGet\Install-Package UtilityVerse.Enum -Version 0.1.0
<PackageReference Include="UtilityVerse.Enum" Version="0.1.0" />
<PackageVersion Include="UtilityVerse.Enum" Version="0.1.0" />
<PackageReference Include="UtilityVerse.Enum" />
paket add UtilityVerse.Enum --version 0.1.0
#r "nuget: UtilityVerse.Enum, 0.1.0"
#:package UtilityVerse.Enum@0.1.0
#addin nuget:?package=UtilityVerse.Enum&version=0.1.0
#tool nuget:?package=UtilityVerse.Enum&version=0.1.0
๐งญ EnumVerse ยท UtilityVerse.Enum

Enum to string conversion using source generation, with typed parsing and member lists. Use custom text, aliases, and flags through concrete extension methods generated in your enum's namespace.
Release 0.1.0
The initial release includes nullable formatting, source and external enum
registration, cached read-only member lists, and diagnostics UVE001โUVE004.
The runtime attribute assembly targets .NET Standard 2.0; the separate analyzer
requires a compiler host compatible with Roslyn 4.11+.
Release notes and compatibility.
๐ Get started
dotnet add package UtilityVerse.Enum
You do not normally need to change LangVersion to use this package. With a
compatible compiler host, the default C# versions for .NET 6 and newer support
conversions and class-qualified list calls.
| Call | Required language version |
|---|---|
status.ToStr(), text.ToOrderStatus() and their Try variants |
C# 10+ |
OrderStatusEnumVerseExtensions.ToList() and other class-qualified list calls |
C# 10+ |
OrderStatus.ToList(), .ToNamesList() and .ToValuesList() |
C# 14+ |
The examples below use the optional C# 14 enum-qualified list syntax. If your project already selects C# 14 or newer, no setting is needed. To use that syntax when the target defaults to an older language version, use a .NET 10+ SDK and set:
<PropertyGroup>
<LangVersion>14.0</LangVersion>
</PropertyGroup>
This selects compiler syntax; it does not change the target runtime. To keep C# 10โ13, use the generated static class for lists instead. See the complete API and fallback example.
A compiler host compatible with Roslyn 4.11+ is required in either case. The current generated code uses file-scoped namespaces, so C# versions below 10 are not supported. Targets such as .NET Standard 2.0 and .NET Framework default to C# 7.3; consumers targeting them must explicitly select C# 10 or newer with a compatible compiler. Older targets are compile-checked, not executed; selecting a newer language version is not a claim of Microsoft-supported language/target combinations. See Microsoft's language-version defaults.
using System;
using UtilityVerse.Enum;
var status = "in-progress".ToOrderStatus();
Console.WriteLine(status.ToStr()); // in-progress
if ("DONE".TryToOrderStatus(out var done, ignoreCase: true))
{
Console.WriteLine(done.ToStr()); // Done
}
// C# 14+: all generated methods live in OrderStatusEnumVerseExtensions.
var entries = OrderStatus.ToList(); // IReadOnlyList<Entry>: Value and Name
var names = OrderStatus.ToNamesList(); // IReadOnlyList<string>: configured text
var values = OrderStatus.ToValuesList(); // IReadOnlyList<OrderStatus>
if (entries[1].Value != OrderStatus.Active || entries[1].Name != "in-progress" ||
names[1] != "in-progress" || values[1] != OrderStatus.Active)
{
throw new Exception("Member-list conversion failed.");
}
[EnumVerse]
public enum OrderStatus
{
Pending,
[EnumVerseName("in-progress")]
Active,
Done
}
๐งพ Register through an enum-valued property
Use the same [EnumVerse] attribute when a DTO references an enum from another
package. This runnable example uses enums from the .NET libraries:
using System;
using System.IO;
using UtilityVerse.Enum;
var dto = new ScheduleDto
{
Day = "Friday".ToWeekday(),
Access = "Read, Write".ToFileAccess()
};
if (dto.Day != DayOfWeek.Friday || dto.Day.ToStr() != "Friday" ||
dto.Access != FileAccess.ReadWrite || dto.Access.ToStr() != "ReadWrite" ||
DayOfWeek.ToList().Count != 7)
{
throw new Exception("Property registration failed.");
}
Console.WriteLine(dto.Day.ToStr()); // Friday
public class ScheduleDto
{
[EnumVerse(Alias = "Weekday")]
public DayOfWeek? Day { get; set; }
[EnumVerse]
public FileAccess? Access { get; set; }
}
The generated extensions live in the enum's namespace in your assembly.
Register each enum type once: either on its declaration or on one property.
Repeated registrations produce UVE004; other properties can use the conversions
without an attribute. Alias is supported on the registering property.
Nullable enum properties are supported; non-enum property types produce UVE001. [EnumVerseName] remains restricted to enum members.
๐ Generated API
For OrderStatus, the generator creates OrderStatusEnumVerseExtensions:
| API | Behavior |
|---|---|
status.ToStr() |
Returns configured text; throws for unsupported values. |
status.TryToStr(out var text) |
Returns false and an empty string on failure. |
nullableStatus.ToStr() |
Returns null for null; present values use the ordinary formatting rules. |
nullableStatus.TryToStr(out var text) |
Returns false and an empty string for null or unsupported values. |
text.ToOrderStatus(ignoreCase: false) |
Parses configured text; throws for null, invalid, or ambiguous input. |
text.TryToOrderStatus(out var status, ignoreCase: false) |
Returns false and the enum's default value on failure. |
OrderStatus.ToList() |
Cached read-only IReadOnlyList<OrderStatusEnumVerseExtensions.Entry> with typed Value/Name pairs. |
OrderStatus.ToNamesList() |
Cached read-only IReadOnlyList<string> with configured strings. |
OrderStatus.ToValuesList() |
Cached read-only IReadOnlyList<OrderStatus> with declared enum values. |
All generated members live in one {EnumName}EnumVerseExtensions class and file.
With C# 14+, extension blocks also allow OrderStatus.ToList(),
OrderStatus.ToValuesList(), and OrderStatus.ToNamesList(), even on older .NET
targets. Lists preserve declaration order and aliases; empty enums produce empty
lists. Repeated calls return the same read-only collection. Mutation is unavailable
through IReadOnlyList<T> and throws NotSupportedException through IList<T>.
Private read-only wrappers keep backing arrays inaccessible. Lists contain declared members only, including named flags combinations.
Older compilers call OrderStatusEnumVerseExtensions.ToList(), .ToNamesList(),
and .ToValuesList(). Class-qualified calls also work when an enum member hides
a method name. Enum types named ToList, ToNamesList, ToValuesList, ToStr,
or TryToStr always use ordinary methods because of C# extension naming rules.
Every conversion method is also callable on that same generated class.
String parsing extensions appear on every string when the enum's namespace is imported. Their presence does not make arbitrary input valid; check the Try result. Fully qualified static calls let you parse without importing those extensions.
[EnumVerseName("in-progress")] replaces the member's conversion string.
[EnumVerse(Alias = "State")] changes the generated class to
StateEnumVerseExtensions, with ToState() / TryToState(). Formatting method names stay the same.
๐ท๏ธ Alias for same-named enums
Alias sets the generated class and parsing method prefixes.
[EnumVerse(Alias = "SalesStatus")]
on Sales.Status generates Sales.SalesStatusEnumVerseExtensions; its methods
use ToSalesStatus() / TryToSalesStatus() and ToStr() / TryToStr().
Omit the alias to use the enum's simple name as the class and parsing method prefix.
When same-named enums are imported together, use distinct aliases to select the enum through its parsing method name. Class-qualified parsing calls also work. Formatting resolves by the enum receiver type. Distinct aliases resolve class-name collisions within the same namespace. Register external enums on one DTO property each.
Alias must be a nonempty C# identifier without @; it does not change enum types
or member strings. Use [EnumVerseName] to change a member's text instead.
See the complete runnable cross-assembly example.
Existing aliased registrations must update parsing calls to use the alias:
ToStatus() / TryToStatus() become ToSalesStatus() / TryToSalesStatus()
for Alias = "SalesStatus", including class-qualified calls.
Unaliased registrations are unchanged.
Nullable enums
Both enum and nullable-enum properties can register their underlying enum with
[EnumVerse]; registering both for the same type produces UVE004. Nullable
formatting preserves null in ToStr() and returns false with an empty string in
TryToStr(). Custom names, flags, and invalid-value handling stay the same for
present values. Parsing methods keep their non-nullable output types; assign a
successful result to a nullable variable, or use the Try result to choose null.
Lists contain declared enum members only, with no added null entry.
๐ฉ Names, aliases, and flags
- Parsing is ordinal and case-sensitive by default. Set
ignoreCase: truefor ordinal ignore-case matching; ambiguous matches fail. - Every alias parses. Formatting picks the first declared name for a value.
[Flags]enums accept comma-separated configured names with spaces around tokens. Exact named combinations take priority; other combinations format in bit order using declared single-bit members.- Invalid flags tokens and unknown bits fail. Zero formats when a zero member exists.
- Ordinary enum strings preserve whitespace exactly. Numeric text parses only when explicitly configured as a name.
๐งฉ Requirements
The package targets .NET Standard 2.0 and requires a compiler host compatible with Roslyn 4.11+. Public/internal source enums and accessible nested enums in non-generic owners are supported, with all eight integer underlying types. Import the enum's namespace to use its generated extensions.
Obsolete members remain convertible and appear in lists without introducing obsolete-member references into generated code.
The package separates runtime attributes from the compiler generator. The runtime
DLL has no Roslyn dependency; the generator DLL is installed only as an analyzer.
Generated parsing names hidden by existing string methods, such as ToString()
and ToLower(), produce UVE002; rename the enum or set an alias that avoids the conflicting parsing name.
Apply [EnumVerse] to an enum declaration or an enum-valued property.
[EnumVerseName] applies only to enum members. Applying either to a class,
or [EnumVerseName] to a property, produces a compiler error;
[EnumVerseName] on a class or struct field produces error UVE003.
Runtime conversions use typed generated code without runtime reflection, dictionaries, generic conversions, or enum boxing. Declared-value formatting returns cached strings. Unnamed flags formatting and flags token parsing can allocate.
Updating earlier examples
For development prototype examples, use the generated class suffix
EnumVerseExtensions (plural). Replace Entries, Names, and Values property
access with ToList(), ToNamesList(), and ToValuesList(). List calls return
cached, read-only collections. Conversion method names stay the same. Version
0.1.0 is the first public release.
๐ Documentation and runnable examples
The package includes examples.md, README.md, XML API documentation, its icon,
and the full MIT license in LICENSE.txt.
Each C# block in examples.md is a complete program checked against the installed
package on .NET 8 and .NET 11. It covers everyday usage and edge cases for people
and coding agents.
| Product | Versions 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 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. |
-
.NETStandard 2.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 |
|---|---|---|
| 0.1.0 | 0 | 12/3/2026 |