ardalis / SmartEnum

A base class for quickly and easily creating strongly typed enum replacements in C#.
MIT License
2.16k stars 169 forks source link

Add support for NRT #511

Open fiseni opened 5 months ago

fiseni commented 5 months ago

Hi,

It would be nice to enable the NRT in the library. It will offer a better experience for the consumers and fix some subtle issues. But. I don't think we'll be able to do that with the current structure (at least I couldn't). I'd suggest constraining the TValue generic parameter to struct.

public abstract class SmartEnum<TEnum, TValue> :
    ISmartEnum,
    IEquatable<SmartEnum<TEnum, TValue>>,
    IComparable<SmartEnum<TEnum, TValue>>
    where TEnum : SmartEnum<TEnum, TValue>
    where TValue : struct, IEquatable<TValue>, IComparable<TValue>

Conceptually, that makes sense. But, it would require some substantial refactoring and will be a major breaking change. I'm not sure if anyone is using reference types as enum values, but there are such users probably.

fiseni commented 5 months ago

Ok, I see a lot of consumers are using string as the enum value. It's even provided as a sample in docs here. So, constraining to struct won't be a good idea. I'll give it another try enabling the NRT in the current form.