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

Duplciate case label value #66

Open
TrueBurn opened this issue Jun 14, 2023 · 2 comments
Open

Duplciate case label value #66

TrueBurn opened this issue Jun 14, 2023 · 2 comments

Comments

@TrueBurn
Copy link

If you have an enum where one value is equal to another value then when you generate the extensions you get a CS8510 error.

Example Enum:

[EnumExtensions]
public enum GroupLevel
{
    Clear,  // Mapped to null
    Root = 1,
    Marketplace = 2,
    Partner = 3,
    Reseller = Partner,
    Company = 4,
    Customer = Company,
    BaseProduct = 5,
    Product = 6
}

Example of generated code:

public static string ToStringFast(this global::Redstor.ModelShared.Enums.GroupLevel value)
            => value switch
            {
                global::Redstor.ModelShared.Enums.GroupLevel.Clear => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Clear),
                global::Redstor.ModelShared.Enums.GroupLevel.Root => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Root),
                global::Redstor.ModelShared.Enums.GroupLevel.Marketplace => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Marketplace),
                global::Redstor.ModelShared.Enums.GroupLevel.Partner => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Partner),
                global::Redstor.ModelShared.Enums.GroupLevel.Reseller => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Reseller),
                global::Redstor.ModelShared.Enums.GroupLevel.Company => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Company),
                global::Redstor.ModelShared.Enums.GroupLevel.Customer => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Customer),
                global::Redstor.ModelShared.Enums.GroupLevel.BaseProduct => nameof(global::Redstor.ModelShared.Enums.GroupLevel.BaseProduct),
                global::Redstor.ModelShared.Enums.GroupLevel.Product => nameof(global::Redstor.ModelShared.Enums.GroupLevel.Product),
                _ => value.ToString(),
            };

image

Error message: The pattern is unreachable. It has already been handled by a previous arm of the switch expression or it is impossible to match.

@pippinmole
Copy link

Hi,

Is this not just because of the way you've structure your enum? You have Reseller = Partner, meaning Reseller == 3. By having this, you can never match to reseller because it would have already been matched to Partner first.

Take the example of running GroupLevel.Reseller.ToStringFast() - it would match on Partner and exit.

@andrewlock
Copy link
Owner

Hi, sorry for the delay in getting to this. To be honest, I'm not sure the best way to handle it 🤔 It is annoying that it won't even compile...

Maybe the answer is to simply not generate the ToStringFast() method in this case 🤔 The inconsistency is a bit annoying though... Maybe we just can't support this kind of enum

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

3 participants