Support static readonly values in switch expressions #7736
Unanswered
hach-que
asked this question in
Language Ideas
Replies: 1 comment 9 replies
-
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've written a string-based enum library that allows you to define enumeration types like this:
You can then use the values like
Example.FirstValue
and parse them withExample.Parse("...")
(inherited from StringEnum).The problem is that matching against these (effectively constant) values is a pain. The following doesn't work, because static readonly fields aren't a constant expression, and as far as I can tell, there's no way for a user-defined type to ever work in a
public const
field. This means that you have to write this:instead of what you really want to write, which is this:
Beta Was this translation helpful? Give feedback.
All reactions