// momentum

+0โ˜… ยท 1 issue ยท 2w

// why it's here

  • Active: last commit today
  • Built almost entirely by one person
  • Health 100/100 with only 24 stars
  • Accepts sponsorship (github, buy me a coffee)

// how to help

// readme

credfeto-enum-source-generation

C# Source generator for enums

Using

Add a reference to the Credfeto.Enumeration.Source.Generation package in each project you need the code generation to run.

<ItemGroup>
  <PackageReference
            Include="Credfeto.Enumeration.Source.Generation"
            Version="1.0.0.11"
            PrivateAssets="All" ExcludeAssets="runtime" />
</ItemGroup>

For each enum in the project, generates a class with the following extension methods:

  • public static string GetName(this MyEnum value)
  • public static string GetDescription(this MyEnum value)

Given an the example enum defined below:

public enum ExampleEnumValues
{
    ZERO = 0,

    [Description("One \"1\"")]
    ONE = 1,

    SAME_AS_ONE = ONE,
}

To get the name and value of the enum values. In release mode this can be practically instant.

ExampleEnumValues value = ExampleEnumValues.ONE;
 string name = value.GetName(); // ONE
 string description = value.GetDescription(); // One "1"
 bool isDefined = value.IsDefine(); // true
 bool isNotDefined = ((ExampleEnumValues)42).IsDefine(); // false
Read the full README on GitHub โ†—