Skip to content

Feature suggestion: Compile-time reflection of string literal unions and enums #9182

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

Closed
XorgonTheTypesafe opened this issue Jun 15, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@XorgonTheTypesafe
Copy link

say we have

type Fish = "one" | "two" | "red" | "blue";

or

enum Fish
{
   one,
   two,
   red,
   blue
}

It would be useful to have a way to refer to the possible values at runtime:
something like __valuesof(Fish) would transpile to
["one" , "two" , "red", "blue"] in both cases.

Also consider __enummap(Fish) that would transpile to

{
    "one":1,
    "two":2,
    "red":3,
    "blue":4    
}

or explicit enum values if specified. This would allow C#'s Enum.Parse functionality

@mhegazy
Copy link
Contributor

mhegazy commented Jun 15, 2016

The issue of type serialization/"reflection" has been discussed multiple times (#2902, #2577, #3060). we already have #3628 to track this discussion; so i suggest moving this proposal to that issue.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jun 15, 2016
@mhegazy mhegazy closed this as completed Jun 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants