Meziantou.Framework.FastEnumToStringGenerator 1.0.4

Generate a faster ToString method for enumerations

Install-Package Meziantou.Framework.FastEnumToStringGenerator -Version 1.0.4
dotnet add package Meziantou.Framework.FastEnumToStringGenerator --version 1.0.4
<PackageReference Include="Meziantou.Framework.FastEnumToStringGenerator" Version="1.0.4">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Meziantou.Framework.FastEnumToStringGenerator --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Meziantou.Framework.FastEnumToStringGenerator, 1.0.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Meziantou.Framework.FastEnumToStringGenerator as a Cake Addin
#addin nuget:?package=Meziantou.Framework.FastEnumToStringGenerator&version=1.0.4

// Install Meziantou.Framework.FastEnumToStringGenerator as a Cake Tool
#tool nuget:?package=Meziantou.Framework.FastEnumToStringGenerator&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Meziantou.Framework.FastEnumToStringGenerator

The source generator generates a ToStringFast method for some enumerations

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

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

The source generator adds the following code:

internal static partial class FastEnumToStringExtensions
{
    internal static string ToStringFast(this Sample.Color value)
    {
        return value switch
        {
            case Blue => "Blue",
            case Red => "Red",
            case Green => "Green",
            _ => value.ToString(),
        };
    }
}

You can now replace the ToString method with the new ToStringFast method:

Color value = Color.Green;
Console.WriteLine(value.ToStringFast());

Additional resources

Meziantou.Framework.FastEnumToStringGenerator

The source generator generates a ToStringFast method for some enumerations

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

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

The source generator adds the following code:

internal static partial class FastEnumToStringExtensions
{
    internal static string ToStringFast(this Sample.Color value)
    {
        return value switch
        {
            case Blue => "Blue",
            case Red => "Red",
            case Green => "Green",
            _ => value.ToString(),
        };
    }
}

You can now replace the ToString method with the new ToStringFast method:

Color value = Color.Green;
Console.WriteLine(value.ToStringFast());

Additional resources

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.4 196 7/14/2021
1.0.3 59 6/30/2021
1.0.2 268 6/21/2021
1.0.1 106 6/16/2021
1.0.0 106 6/16/2021