Code Monkey home page Code Monkey logo

jcd.richenumerations's Introduction

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

jcd.richenumerations's People

Contributors

jason-c-daniels avatar

Watchers

 avatar

jcd.richenumerations's Issues

Add performance benchmarks.

Task Description

Add a performance benchmark project based on BenchmarkDotNet.

Motivation

This is so that people can evaluate how well it performs in situ.

Additional Context

Performance benchmarks let people evaluate if the code is fast enough for their purposes.

Add Flag type rich enumerations

Request Summary

Add support for rich enumerations that are flags. (e.g. bit position 1 set means one thing, bit position 2 another...etc. With only a need to define the meaning of the bit positions, not the entire set of all possible flags)

Proposed Resolution

For both record and class based RichEnum hierarchies add a base typ that can support code similar to as follows:

public class MyFlags(uint flags, string name) : FlagsEnum<MyFlags>(flags)
{
    public static readonly MyFlags Flag1 = new(0b00001,"Flag1");
    public static readonly MyFlags Flag2 = new(0b00010,"Flag2");
    public static readonly MyFlags Flag3 = new(0b00100,"Flag3");
    public static readonly MyFlags SpecialCase = new(0b00101,"SpecialCase");
}

Console.WriteLine(((MyFlags)0b00001).ToString()); // outputs: Flag1
Console.WriteLine(((MyFlags)0b00010).ToString()); // outputs: Flag2
Console.WriteLine(((MyFlags)0b00011).ToString()); // outputs: [Flag1, Flag2]
Console.WriteLine(((MyFlags)0b00100).ToString()); // outputs: Flag3
Console.WriteLine(((MyFlags)0b00101).ToString()); // outputs: SpecialCase
Console.WriteLine(((MyFlags)0b00111).ToString()); // outputs: [Flag1, Flag2, Flag3]

Alternatives

Put a thin wrapper over Ardalis.SmartEnum's FlagsEnum. Downsides - No control, poorly documented. Upside - already implemented.

Additional context

Flags are often used with enums to allow for packing data into a single value.

Add support for record class based rich enumerations.

Request Summary

Add support for record class based rich enumerations. Since C# 10 record classes have gained popularity. Not providing this feature for more modern approaches seems a gross oversight.

Proposed Resolution

Create a parallel set of classes, either in a new namespace w/ same names or with a slightly different naming convention. (e.g. Jcd.RichEnumerations.Records or RichEnumRec...etc.)

Alternatives

Don't provide a mechanism for record classes. After all, public class MyRichEnum : RichEnum<MyRichEnum> ... is very concise.

Additional context

Doing this will require documentation informing users on how to use record types in .net standard libraries.

Create end user documentation

Task Description

Create end user documentation in addition to the auto-generated API documentation.

Motivation

DDD Concepts such as Rich Enumerations are often misunderstood and misapplied. End user documentation should strive to keep the usage of a library clear, including recapping fundamental theory and providing concrete examples.

Do a POC nuget package build and push to MyGet.

Task Description

Do a POC nuget package build and push to MyGet. Then consume the package from MyGet to ensure it works in the intended target environments. (Ubuntu, Windows 11)

Motivation

Ensuring the build product and pipeline function as expected is essential to keeping a library up to date with minimal fuss.

Assess current namespaces and convenience types.

Task Description

Assess the appropriateness of the current namespaces and convenience types (e.g. NamedRichEnum).

Motivation

A good naming strategy for both components and namespaces is necessary for a successful library. As well too many convenience types can obscure the purpose of the types a library provider intends to make their focus.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.