Skip to content

extension enum #4329

Open
Open
@kirara-shiroyoru

Description

@kirara-shiroyoru

When I need a set options(typically for switch), no run-time type check required, enum in dart is an over-kill, I would use extension type and static const variables instead.

Just like using the same syntax in a class, it is verbose, therefore I expect a feature similar to enum as extension type. Though not having it would be fine, having it would be great.

This is how it would look like right now

extension type const SudoEnum(int i){
  static const option1 = SudoEnum(1);
  static const option2 = SudoEnum(2);
  static const option3 = SudoEnum(3);
}

And this is what I expect it to be

//For the constructor representing underlying structure,
//extension enum is always const, 
//I think const keyword should be omitted.
extension enum SudoEnum(int i){
  option1(1), option2(2), option3(3);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions