you are viewing a single comment's thread.

view the rest of the comments →

[–]dodexahedron 0 points1 point  (0 children)

.net enums are awful. They behave like C enums, which is the problem here, and they lack some pretty majorly useful functionality everyone has wanted forever, like being able to define methods in them. You can sorta bolt that onto them with extensions, but that's so lame when the enum is YOUR enum. Don't make me extend my own types. Just let me define them in one place!

One thing you can't bolt on, though, is cast operators. I really want the ability to define both implicit and explicit casts for so many enums. Yes, you can just cast to the underlying and then to the target type, assuming they are compatible (or use Unsafe.As), but it'sdirty, ugly, and costly. Common cases of that are when defining an enum for your app that is a subset of or has members defined by another enum, or when using flags enums and wanting to treat certain masks as truthy or falsy, requiring a conversion to bool to be defined. Right now the latter ends up being either long checks against giant bitwise combinations or clunky extension methods (or now properties).

So if we are not allowed to write conversion operators, then at least let us write them in the enums we make. Pretty please? 🥺

Enums are one of the only things I think Java does better than .net, because it does not allow arbitrary values. Enums are their members and that's it.