FinalEnumGenerator 3.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FinalEnumGenerator --version 3.0.0
NuGet\Install-Package FinalEnumGenerator -Version 3.0.0
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="FinalEnumGenerator" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FinalEnumGenerator" Version="3.0.0" />
<PackageReference Include="FinalEnumGenerator" />
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 FinalEnumGenerator --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FinalEnumGenerator, 3.0.0"
#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 FinalEnumGenerator@3.0.0
#: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=FinalEnumGenerator&version=3.0.0
#tool nuget:?package=FinalEnumGenerator&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
<div align="center">
FinalEnumGenerator
Generates High-Performance string and UTF-8 Extensions for Enums
Unity 2022.3.12+ is supported
</div>
- Generates high-performance
ToStringFast(),ToStringUtf8(), andTryParse()methods. - Adds helpers
GetNames(),GetValues(),GetNamesUtf8(), andIsDefined(long/ulong)on the enum type. - Supports display names from
InspectorNameAttribute(Unity compatibility) orCategoryAttribute. - Emits diagnostics for non-public containing types and ambiguous/invalid display names.
🚀 Getting Started
The sample code talks enough.
using FinalEnumGenerator;
[FinalEnum]
[Flags]
public enum MyEnum
{
None = 0,
// Customize name by Category attribute from System.ComponentModel
// to avoid unnecessary dependency to FinalEnum
[Category("日本語")]
Flag1 = 1,
Flag2 = 2,
// Non-alphanumerics are supported ofcourse!
[Category("ひらがな \"français\" カタカナ")]
Flag3 = 4,
Flag4 = 8,
// ERROR: Display name cannot have ',' to avoid ambiguity of Flags enums
[InspectorName("子,丑,寅,卯,辰,巳,午,未,申,酉,戌,亥")] // InspectorName can be used (Unity)
InspectorNameAttribute_from_Unity = 16,
}
Here shows how to use the generated extensions.
using FinalEnums;
using FinalEnums.EnumNamespace; // Methods are generated in FinalEnums namespace
if (MyEnum.TryParse("日本語", out var value))
{
var text = value.ToStringFast();
var utf8 = value.ToStringUtf8();
}
// GetNames/Values always allocates array
var allNames = MyEnum.GetNames();
var allValues = MyEnum.GetValues();
// Utf8 byte arrays are cached internally but array of ReadOnlyMemory allocates
var allUtf8Arrays = MyEnum.GetNamesUtf8();
// Check by underlying primitive
if (MyEnum.IsDefined(100))
{
// accepts `long` or `ulong` depending on the Enum shape
}
🕹️ Technical Specs
TryParsechecks string/byte length first and uses delimiter-aware token matching (including[Flags]).[Flags]fast-path uses a switch for single flags and falls back to a builder for combined values; combined string/UTF-8 outputs allocate only in that fallback path.TryParsesupports bothstringandReadOnlySpan<byte>.stringpath accepts aStringComparisonand always trims input.- UTF-8 path can optionally ignore whitespace separators.
- The generated members live in
FinalEnums.<Namespace>.<ContainingTypes>.<EnumName>and reuse shared helpers inFinalEnums.FinalEnumUtility(throw helper, boundary-awareContainsToken). [Flags]parsing:- Delimiter-aware token matching succeeds when at least one known token is present; unknown tokens are ignored rather than rejected.
- Commas are rejected for
[Flags]display names to keep parsing unambiguous.
- Display name diagnostics include empty/whitespace-only, leading/trailing whitespace, commas, and overlapping tokens; matching is case-insensitive after trimming.
TryParse always allows fuzzy match (can contain undefined name).
ToStringFast/Utf8 does not allow converting undefined value.
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.