EpicEnums 1.2023.7.291844

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

// Install EpicEnums as a Cake Tool
#tool nuget:?package=EpicEnums&version=1.2023.7.291844                

Epic Enums

Think the standard C# enums are boring? Yeah, same! Lets improve that.

What does it solve/improve on?

Common c# enums are a powerfull tool for constant data. They are fast and simple. However they sometimes lack the flexibility that you want in a complex application.

Here is a standard C# enum like we all know:

public enum FruitsEnum
{
    Apple,
    Banana,
    Orange,
    DragonFruit
} 

All pretty standard nothing special, however if we want to tie some extra properties to our fruit then things get a little tricky. We could of course add an attribute and make it work:

public enum FruitsEnum
{
    [Display(Name = "Apple")]
    Apple,
    [Display(Name = "Banana")]
    Banana,
    [Display(Name = "Orange")]
    Orange,
    [Display(Name = "Dragon Fruit")]
    DragonFruit
} 

First of all, this is not very readable and can get messy quickly. Most importantly: To access these values you have to write code using reflection to access these properties: (as per stackoverflow)

public static class Extensions
{
    /// <summary>
    ///     A generic extension method that aids in reflecting 
    ///     and retrieving any attribute that is applied to an `Enum`.
    /// </summary>
    public static TAttribute GetAttribute<TAttribute>(this Enum enumValue) 
            where TAttribute : Attribute
    {
        return enumValue.GetType()
                        .GetMember(enumValue.ToString())
                        .First()
                        .GetCustomAttribute<TAttribute>();
    }
}

public class Foo 
{
    public FruitsEnum Fruit = FruitsEnum.Apple;

    public void DisplayName()
    {
        var fruitDisplayName = Fruit.GetAttribute<DisplayAttribute>();
        Console.WriteLine("Which friot is it?");
        Console.WriteLine (fruitDisplayName.Name);
    } 
}

Reflection can be slow and give issues in AOT compiling. Plus it can be kind of tedious.

A Better enum

(The name epic enums was chosen because it alliterats ever so lovely)

Installing the package

The epic enums package can be found on nuget.

dotnet add package EpicEnums

Creating your first Epic Enum

Epic Enums works based on source generation, but needs some work from you as a developer.

Warning: Epic enums has some guidelines on how to work with them. If you dont follow these guidelines unexpected behaviour might happen.

The value record

using EpicEnums;

namespace SampleApp.NotVegetables;

public partial record Fruit : IEpicEnumValue  // It is very important that this is a partial record
{
    public required string Name { get; init; }
    public required string Description { get; init; }
    public required bool LikeAble { get; init; }
}

The enum record

using EpicEnums;

namespace SampleApp.NotVegetables;

public partial record Fruits : EpicEnum<Fruit>
{
    public static Fruit Apple { get; } = new() { Name = "Apple", Description = "A red fruit", LikeAble = true };
    public static Fruit Banana { get; } = new() { Name = "Banana", Description = "A yellow fruit", LikeAble = true };
    public static Fruit Orange { get; } = new() { Name = "Orange", Description = "An orange fruit", LikeAble = false };
    public static Fruit DragonFruit { get; } = new() { Name = "Dragon Fruit", Description = "A pink fruit", LikeAble = true };
}
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.

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.2023.10.231942 312 10/23/2023
1.2023.10.231827 137 10/23/2023
1.2023.10.182059 123 10/18/2023
1.2023.8.31931 159 8/3/2023
1.2023.7.310908 158 7/31/2023
1.2023.7.301221 205 7/30/2023
1.2023.7.301215 158 7/30/2023
1.2023.7.301213 152 7/30/2023
1.2023.7.301040 148 7/30/2023
1.2023.7.291844 166 7/29/2023
1.2023.7.291842 153 7/29/2023
1.2023.7.291832 138 7/29/2023
1.2023.7.291628 158 7/29/2023
1.2023.7.291624 154 7/29/2023
1.2023.7.291615 166 7/29/2023
1.2023.7.291611 178 7/29/2023
1.2023.7.291608 180 7/29/2023
1.2023.7.291606 165 7/29/2023
1.2023.7.291553 144 7/29/2023
1.2023.7.291551 251 7/29/2023
1.0.0 160 7/29/2023