ardalis / SmartEnum

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

Revert PR 412 and remove support for null values. #512

Open fiseni opened 8 months ago

fiseni commented 8 months ago

The premise of this library is that it can extend the built-in enum types in .NET, but still, it will mimic the behavior of the enum types. SmartEnums even though defined as classes, they're extended to offer value-type behavior.

This PR enables creating a SmartEnum with a null value. This breaks the assumed contract and leads to various inconsistencies. For instance, we can no longer guarantee that SmartEnum can be used as dictionary keys.

var types = new Dictionary<CustomerType, object>();

types.Add(CustomerType.One, new()); // Will throw

public class CustomerType : SmartEnum<CustomerType, string>
{
    public static CustomerType One = new CustomerType("One", null);
    public static CustomerType Two = new CustomerType("Two", "two");
    protected CustomerType(string name, string value) : base(name, value) { }
}
fiseni commented 8 months ago

/cc @MisinformedDNA, adding you to the loop, so you're notified of the potential changes here.