EnumScribe 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EnumScribe --version 1.1.0
NuGet\Install-Package EnumScribe -Version 1.1.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="EnumScribe" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EnumScribe --version 1.1.0
#r "nuget: EnumScribe, 1.1.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.
// Install EnumScribe as a Cake Addin
#addin nuget:?package=EnumScribe&version=1.1.0

// Install EnumScribe as a Cake Tool
#tool nuget:?package=EnumScribe&version=1.1.0

<h1 align="center" style="text-align: center">

EnumScribe </h1>

<h1 align="center" style="text-align: center">

Nuget Downloads </h1>

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
  • Analyzer warning for unnecessary NoScribe attributes
  • 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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in 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.1.1 446 1/19/2022
1.1.0 399 1/13/2022
1.0.1 262 12/9/2021
1.0.0 264 12/8/2021