A netstandard2.0 library that provides DDD-style rich enumeration base types for both plain old
classes and record
types.
// 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.
}