Enum.Ext 1.0.1.1

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

// Install Enum.Ext as a Cake Tool
#tool nuget:?package=Enum.Ext&version=1.0.1.1                

Enum.Ext

Build Status Version

Enum.Ext provides a TypeSafeEnum that has a bunch of advantages compared to the normal .NET Enum value type.

For example is it possible to store additional information directly with the enum. You are later on able to query an enum based on the information stored with it.

There is also a Json-Serializer implemented, so you dont have to cast from DTOs manually.

Installation

https://www.nuget.org/packages/Enum.Ext/

Enum.Ext can be installed using the following command via the NuGet package manager console:

PM> Install-Package Enum.Ext

How to use

Simply inherit your class from TypeSafeEnum or TypeSafeNameEnum and adjust everything to your needs.

Want a weekday enum with a special string representation for each day?
public sealed class Weekday : TypeSafeNameEnum<Weekday, int>
{
    public static readonly Weekday Monday = new Weekday(1, "--Monday--");
    public static readonly Weekday Tuesday = new Weekday(2, "--Tuesday--");
    public static readonly Weekday Wednesday = new Weekday(3, "--Wednesday--");
    ....

    public Weekday(int id, string name) : base(id, name)
    {
    }
}

Use the enum just like the native one

var day = Weekday.Monday;

// Assigns Tuesday
day = (Weekday)2;

and access the additional information easily

var day = Weekday.Monday;

// Prints out '--Monday--'
Console.WriteLine(day.Name);

Enum.Ext in action

Here you find some examples how you could use the extension.

A fixed price that is valid for a certain time period
public sealed class YearlyPrice : TypeSafeEnum<YearlyPrice, int>
{
    public decimal Price { get; private set; }

    public DateTime ValidFrom { get; private set; }

    public DateTime ValidTo { get; private set; }

    public static readonly YearlyPrice Price_2018 =
        new YearlyPrice(1, 15.99m, new DateTime(2018, 1, 1), new DateTime(2018, 12, 31));

    public static readonly YearlyPrice Price_2019 =
        new YearlyPrice(2, 16.99m, new DateTime(2019, 1, 1), new DateTime(2019, 12, 31));

    public YearlyPrice(int id, decimal price, DateTime validFrom, DateTime validTo) : base(id)
    {
        ValidFrom = validFrom;
        ValidTo = validTo;
        Price = price;
    }

    public static YearlyPrice GetPriceByDate(DateTime date)
    {
        // The List property holds all elements declared above
        return List.FirstOrDefault(x => x.ValidFrom <= date && date <= x.ValidTo);
    }
}

Get the according enum for a given date

DateTime date = new DateTime(2018, 5, 3);

// Returns YearlyPrice.Price_2018
var price = YearlyPrice.GetPriceByDate(date);
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 (8)

Showing the top 5 NuGet packages that depend on Enum.Ext:

Package Downloads
Enum.Ext.EFCore

Entity framework core support for Enum.Ext

Enum.Ext.SystemTextJson

This package adds System.Text.Json converters for Enum.Ext

Enum.Ext.NewtonsoftJson

This package adds Newtonsoft.Json converters for Enum.Ext

Enum.Ext.AutoFixture

AutoFixture support for Enum.Ext

VatEurope

a small library to validate vat-numbers in europe

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.7 24,962 11/19/2021
1.0.6 9,908 10/20/2019
1.0.4 1,464 7/2/2019
1.0.3 871 6/22/2019
1.0.2 763 6/21/2019
1.0.1.1 740 6/21/2019
1.0.1 564 6/21/2019
1.0.0.1 528 6/20/2019
1.0.0 557 6/20/2019