EnumScribe 1.1.1

.NET Standard 2.0
Install-Package EnumScribe -Version 1.1.1
dotnet add package EnumScribe --version 1.1.1
<PackageReference Include="EnumScribe" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EnumScribe --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EnumScribe, 1.1.1"
#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 EnumScribe as a Cake Addin
#addin nuget:?package=EnumScribe&version=1.1.1

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

EnumScribe

An easy-to-use source generator providing efficient access to enum description text.

Why?

When binding an enum to a UI component, it's uncommon to be able to display the enum identifier itself, EG. "OutOfStock" doesn't adhere to english grammar. Working around this usually either comes with a runtime cost (reflection) or maintainability cost (manual enum → text mapping)

EnumScribe simplifies the process by generating the mapping at compile time based on Description attributes and exposing it via properties added to the type, making the text easier to consume in most UI frameworks.

Features

  • Create additional properties returning the matching enum's description
  • Implement available partial methods instead of creating new properties
  • Customise the default suffix ("Description")
  • Selectively scribe enums by accessibility and member type
  • Ignore individual enums with NoScribe
  • Opt out of serializing generated properties with JsonIgnore (Supports Json.NET and System.Text.Json)
  • Access descriptions for scribed enums directly by using the DescriptionText() extension method (included in the EnumScribe.Extensions namespace)

Basic usage

using EnumScribe;

// Source code
[Scribe]
public partial class MyDto
{
    public MyEnum? ToProperty { get; set; }

    public MyEnum ToMethod { get; set; }
    public partial string ToMethodDescription();

    [NoScribe]
    public MyEnum HiddenProperty { get; set; }
}

// Generated code
public partial class MyDto
{
    // "ToProperty" + "Description"
    public string? ToPropertyDescription { get { /* ... */ } }
    // "ToMethod" + "Description"
    public partial string ToMethodDescription() { /* ... */ }
}

Troubleshooting

No code is being generated :(

Source generators are a relatively new feature and are still facing some intermittent teething issues (EG. #49249)

Most issues are addressed by cleaning the project, then restarting your IDE and rebuilding it.

It can be helpful to opt into outputting generated files by including the below snippet in the consuming project. While these are normally viewable in the VS solution explorer (Dependencies\Analyzers\EnumScribe) it's not entirely reliable yet.

  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    
    <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  </PropertyGroup>

Definition cannot be found

Compiler errors CS1061 and CS8795 warns of missing or unimplemented type members and may erronously report that generated code is missing. This may presist through project rebuilds, but can usually be resolved by restarting your IDE.

Planned work

  • Update to source generators 2.0 (IIncrementalGenerator)
  • Proper tests (pending package update)
  • Benchmarks
  • Localise diagnostic text
  • Scribe T in generic types where T is an enum
  • New attribute ReScribe to manually override scribe rules on a property/field basis (suffix, accessibility, json ignore)
  • Acknowledge ReScribe attribute on property without the containing class requiring ScribeEnum
  • Scribe functionality for structs and record structs
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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.1.1 80 1/19/2022
1.1.0 72 1/13/2022
1.0.1 104 12/9/2021
1.0.0 92 12/8/2021