-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Proposal: Implicit Enums #8272
Comments
Public contract should never be inferred from usage. It would be too difficult to discern and too easy to break accidentally. |
@HaloFour So if you actually declare it like void F(Options options) {
enum Options { Yes, No } // ideally, nested
switch(options) { ... }
} did you change anything? |
@alrz I'm not aware of any other place in C# where something declared within a method would leak out of that method as part of a public contract. C# has no concept of local types, but if it did why should it differ from, say, local classes in Java, where they can't be referenced outside of their declaring method, and you cannot define parameters of that method of that class? I don't see what having the declaration nested gets you. The |
With inline enumerations (#3497) one can define an
enum
within parameter declaration,and with #952 you can simply call it,
But the question is, how are you going to use it? Perhaps with a
switch
statement or expression,As you can see, you have to repeat all the enum members in
switch
cases and in parameter type itself which might get long and turn into an ugly parameter list. To address this, I want to propose implicit enums in method parameters which can infer members from theswitch
statement,With enum records (#6739) you can use pattern matching to destruct the input,
In this case an
enum class
would be generated by the compiler,DRY.
The text was updated successfully, but these errors were encountered: