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

Composite enums #1079

Closed
ghost opened this issue Nov 5, 2017 · 6 comments
Closed

Composite enums #1079

ghost opened this issue Nov 5, 2017 · 6 comments

Comments

@ghost
Copy link

ghost commented Nov 5, 2017

It would be great to have a composite enums. What do you think about this idea?

enum Color {
    Blue {
        CadetBlue,
        SkyBlue,
        Turquoise
    },
    Red,
    Green
}

It would be great to just write (with intellisense): var x = Color.Blue.SkyBlue

Currently I often use enums like BlueCadet, BlueSky, BlueTurquoise because I am lazy and want Visual Studio to quickly offer exactly what I do want.

edit: I program automata with many states which I like to be compile constants. That's reason why I have enums with a lot of values and very similar names. It is nearly impossible to distinguish them and something like "folders" would help. I want to recycle some names and composite enums would be an option.

edit: I would also like to write something like: case Blue in switch. That could be just copying of the code from Blue case into Blue.CadetBlue, etc.

edit: It would be also possible to do nothing with enums and introduce something like groups. It could look like:

group Blue from Color {
    CadetBlue,
    SkyBlue,
    Turquoise
}

It would be possible to access for example Blue.SkyBlue like an equivalent of Color.SkyBlue. Also it would be possible to write:

Color a = ...
switch(a) {
    case Blue:
    ...
}
@MkazemAkhgary
Copy link

I like your query style syntax for enums, that's something to think about in wider use cases...

@kxxt
Copy link

kxxt commented Nov 5, 2017

Good idea!
I love it!😃😃😃

@Joe4evr
Copy link
Contributor

Joe4evr commented Nov 5, 2017

And how do you propose this is represented under the covers? How will the compiler know which enum values have sub-values and which don't to provide accurate IntelliSense? What kind of code will the compiler spit out for your case of case Blue matching all the sub-values of Blue?

These are questions you need to provide an answer for.

@ghost ghost closed this as completed Nov 5, 2017
@aluanhaddad
Copy link

I like the idea of nested enums.

@lillo42
Copy link

lillo42 commented Nov 5, 2017

I like the idea too

@bondsbw
Copy link

bondsbw commented Nov 5, 2017

Not the same but related: #587

This issue was closed.
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

No branches or pull requests

6 participants