Meziantou.Framework.FastEnumGenerator 2.0.11

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

Meziantou.Framework.FastEnumGenerator

The source generator generates specialized enum helpers for selected enum types.

[assembly: FastEnumAttribute(typeof(Sample.Color), IsPublic = true, ExtensionMethodNamespace = "Sample.Extensions")]

namespace Sample
{
    public enum Color
    {
        Blue,
        Red,
        Green,
    }
}

Generated methods

For each configured enum, the generator emits these instance extension methods:

  • string ToStringFast(this TEnum value)
  • string ToStringFast(this TEnum value, bool useMetadata)
  • bool HasFlag(this TEnum instance, TEnum flag)
  • string GetName(this TEnum instance)

Method behavior:

  • ToStringFast returns the declared enum name without using reflection.
  • ToStringFast(..., useMetadata: true) uses metadata names when available.
  • GetName is the non-metadata version of ToStringFast.
  • HasFlag uses typed bitwise operations ((instance & flag) == flag).

When the target project supports C# 14 extension members, the generator also emits static members on extension(TEnum):

  • TEnum Parse(string value, bool ignoreCase)
  • TEnum Parse(ReadOnlySpan<char> value, bool ignoreCase)
  • TEnum Parse(string value, bool ignoreCase, bool useMetadata)
  • TEnum Parse(ReadOnlySpan<char> value, bool ignoreCase, bool useMetadata)
  • bool TryParse(string value, bool ignoreCase, out TEnum result)
  • bool TryParse(ReadOnlySpan<char> value, bool ignoreCase, out TEnum result)
  • bool TryParse(string value, bool ignoreCase, bool useMetadata, out TEnum result)
  • bool TryParse(ReadOnlySpan<char> value, bool ignoreCase, bool useMetadata, out TEnum result)
  • bool IsDefined(TEnum value)
  • ReadOnlySpan<string> GetNames(bool useMetadata)
  • ReadOnlySpan<TEnum> GetValues()

Analyzer rules

The package also ships analyzers and code fixes for enums configured with FastEnumAttribute.

  • MFEG0001: invalid FastEnumAttribute enum type
  • MFEG0002: use TEnum.Parse(...) instead of Enum.Parse(...)
  • MFEG0003: use TEnum.TryParse(...) instead of Enum.TryParse(...)
  • MFEG0004: use TEnum.GetNames(useMetadata: false) instead of Enum.GetNames(...)
  • MFEG0005: use TEnum.GetValues() instead of Enum.GetValues(...)
  • MFEG0006: use value.GetName() instead of Enum.GetName(...)
  • MFEG0007: use TEnum.IsDefined(...) instead of Enum.IsDefined(...)
  • MFEG0008: use value.ToStringFast() instead of value.ToString()

Metadata names

useMetadata uses names from:

  • DisplayAttribute.Name
  • DisplayNameAttribute.DisplayName
  • EnumMemberAttribute.Value

When metadata is not available for a member, the declared enum name is used.

Additional resources

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.
  • 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
2.0.11 91 5/24/2026
2.0.10 93 5/23/2026
2.0.9 94 5/17/2026
2.0.8 98 5/15/2026
2.0.7 107 5/14/2026
2.0.6 100 5/11/2026