Skip to content

A library to ease the implementation and use of Rich Enumerations popularized by DDD.

License

Notifications You must be signed in to change notification settings

jason-c-daniels/Jcd.RichEnumerations

Repository files navigation

Jcd.RichEnumerations

A netstandard2.0 library that provides DDD-style rich enumeration base types for both plain old classes and record types.

Examples

// define the rich enum type.

using Jcd.RichEnumerations.Wrappers

// Derive from a simplifying wrapper. In this case one that already defines the description property.
public class MyRichEnum(int value, string description) : DescribedRichEnum<MyRichEnum>(value,description)
{
   public static readonly MyRichEnum Item1 = new(1, "Item 1");
   public static readonly MyRichEnum Item2 = new(2, "Item 2");
   public static readonly MyRichEnum Item3 = new(3, "Item 3");
}

// use the values
int userInput = GetUserInput();

// use the conversion operator to convert the raw number into an instance of the RichEnum.
var  ev = (MyRichEnum) userInput;

if (ev == MyRichEnum.Item1) {
   //.. do something specific to Item1 being selected.
}

Badges

GitHub Build status CodeFactor Grade

MyGet Nuget

API Docs User Guide

About

A library to ease the implementation and use of Rich Enumerations popularized by DDD.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published