Supernova.Enum.Generators 1.0.14

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

// Install Supernova.Enum.Generators as a Cake Tool
#tool nuget:?package=Supernova.Enum.Generators&version=1.0.14

GitHub license Nuget Nuget

<p align="center"> <a href="" target="_blank"> <img src="" height="61" width="194" /> </a> </p>


The best Source Generator for working with enums in C#

A C# source generator to create an enumeration class from an enum type. With this package, you can work on enums very, very fast without using reflection.

Package - Supernova.Enum.Generators

Add the package to your application using

dotnet add package Supernova.Enum.Generators

Adding the package will automatically add a marker attribute, [EnumGenerator], to your project.

To use the generator, add the [EnumGenerator] attribute to an enum. For example:

public enum UserTypeTest
    [Display(Name = "مرد", Description = "Descمرد")] Men = 3,

    [Display(Name = "زن", Description = "Descزن")] Women = 4,

    //[Display(Name = "نامشخص")]

This will generate a class called EnumNameEnumExtensions (UserTypeTest + EnumExtensions), which contains a number of helper methods. For example:

    public static class UserTypeTestEnumExtensions
        public static string ToStringFast(this UnitTests.UserTypeTest states, string defaultValue = null)
            return states switch
                UnitTests.UserTypeTest.Men => nameof(UnitTests.UserTypeTest.Men),
                UnitTests.UserTypeTest.Women => nameof(UnitTests.UserTypeTest.Women),
                UnitTests.UserTypeTest.None => nameof(UnitTests.UserTypeTest.None),
                _ => defaultValue ?? throw new ArgumentOutOfRangeException(nameof(states), states, null)
        public static bool IsDefinedFast(UnitTests.UserTypeTest states)
            return states switch
                UnitTests.UserTypeTest.Men => true,
                UnitTests.UserTypeTest.Women => true,
                UnitTests.UserTypeTest.None => true,
                _ => false
        public static bool IsDefinedFast(string states)
            return states switch
                nameof(UnitTests.UserTypeTest.Men) => true,
                nameof(UnitTests.UserTypeTest.Women) => true,
                nameof(UnitTests.UserTypeTest.None) => true,
                _ => false
        public static string ToDisplayFast(this UnitTests.UserTypeTest states, string defaultValue = null)
            return states switch
                UnitTests.UserTypeTest.Men => "مرد",
                UnitTests.UserTypeTest.Women => "زن",
                UnitTests.UserTypeTest.None => "None",
                _ => defaultValue ?? throw new ArgumentOutOfRangeException(nameof(states), states, null)
        public static string ToDescriptionFast(this UnitTests.UserTypeTest states, string defaultValue = null)
            return states switch
                UnitTests.UserTypeTest.Men => "Descمرد",
                UnitTests.UserTypeTest.Women => "Descزن",
                UnitTests.UserTypeTest.None => "None",
                _ => defaultValue ?? throw new ArgumentOutOfRangeException(nameof(states), states, null)
        public static UnitTests.UserTypeTest[] GetValuesFast()
            return new[]
        public static string[] GetNamesFast()
            return new[]
        public static int GetLengthFast()
            return 3;


You do not see this file inside the project. But you can use it.


var stringEnum = UserTypeTest.Men.ToStringFast(); //Men;

var isDefined = UserTypeTestEnumExtensions.IsDefinedFast(UserType.Men); //true;

var displayEnum = UserTypeTest.Men.ToDisplayFast(); //مرد

var names = UserTypeTestEnumExtensions.GetNamesFast(); //string[]

var values = UserTypeTestEnumExtensions.GetValuesFast(); //UserType[]

var length = UserTypeTestEnumExtensions.GetLengthFast(); //3

If you had trouble using UserTypeTestEnumExtensions and the IDE did not recognize it. This is an IDE problem and you need to restart the IDE once.




Create an issue if you find a BUG or have a Suggestion or Question. If you want to develop this project :

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

Give a Star! ⭐️

If you find this repository useful, please give it a star. Thanks!


Supernova.Enum.Generators is Copyright © 2022 Mohsen Rajabi under the MIT License.

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.0.17 176 3/29/2024
1.0.16 124 3/19/2024
1.0.15 2,252 2/29/2024
1.0.14 110 2/23/2024
1.0.13 9,506 12/4/2022
1.0.12 1,282 5/31/2022
1.0.11 429 5/28/2022
1.0.10 396 5/27/2022
1.0.9 395 5/26/2022
1.0.8 399 5/26/2022
1.0.7 392 5/26/2022
1.0.5 401 5/26/2022
1.0.4 416 5/26/2022
1.0.0 443 5/26/2022

             Added default values for ToStringFast/ToDisplayFast methods.
             Added ToDescriptionFast method.
             Added "DisplayNames" and "DisplayDescriptions" dictionaries to hold static values as dictionaries.