Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fiseni opened this issue Apr 6, 2024 · 1 comment · May be fixed by #518
Open

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

fiseni opened this issue Apr 6, 2024 · 1 comment · May be fixed by #518

Comments

@fiseni
Copy link

fiseni commented Apr 6, 2024

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
Copy link
Author

fiseni commented Apr 6, 2024

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

@fiseni fiseni linked a pull request Apr 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant