PlusUltra.EnumDescriptor.Generator 1.0.2

dotnet add package PlusUltra.EnumDescriptor.Generator --version 1.0.2
NuGet\Install-Package PlusUltra.EnumDescriptor.Generator -Version 1.0.2
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="PlusUltra.EnumDescriptor.Generator" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PlusUltra.EnumDescriptor.Generator --version 1.0.2
#r "nuget: PlusUltra.EnumDescriptor.Generator, 1.0.2"
#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.
// Install PlusUltra.EnumDescriptor.Generator as a Cake Addin
#addin nuget:?package=PlusUltra.EnumDescriptor.Generator&version=1.0.2

// Install PlusUltra.EnumDescriptor.Generator as a Cake Tool
#tool nuget:?package=PlusUltra.EnumDescriptor.Generator&version=1.0.2

ci

Enum description generator

This generates a GetDescription method for Enum

Get Started

All enums with GenerateEnumDescriptorAttribute will be selected to process

You can customize the value using DescriptionAttribute

Installing

dotnet add package PlusUltra.EnumDescriptor.Generator

Decorating enums

[GenerateEnumDescriptor]
public enum MyEnum
{
    [Description("Custom 1")]
    Value1,
    Value2,
    [Description("Custom Value N")]
    ValueN
}

This example will generate:

namespace System
{
    public static class EnumStringExtensions
    {   
        public static string GetDescription(this Namespace.MyEnum value)
        {
            return value switch
            {
                SampleConsole.MyEnum.Value1 => "Custom 1",
                SampleConsole.MyEnum.Value2 => nameof(SampleConsole.MyEnum.Value2),
                SampleConsole.MyEnum.ValueN => "Custom Value N",
                _ => throw new ArgumentException(message: "Invalid enum value", paramName: nameof(value))
            };
        }
    }
}

Now you can use GetDescription instead of ToString;

MyEnum value = MyEnum.Value1;
Console.WriteLine(value.GetDescription());
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .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
1.0.2 347 10/2/2021
1.0.1 285 10/2/2021
1.0.0 292 10/2/2021