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

Flags enums should be sorted #3796

Open
verdie-g opened this issue Feb 7, 2024 · 1 comment
Open

Flags enums should be sorted #3796

verdie-g opened this issue Feb 7, 2024 · 1 comment

Comments

@verdie-g
Copy link

verdie-g commented Feb 7, 2024

I would like to suggest a new rule that, with an enum like that

[Flags]
public enum AttrCapabilities
{
    AllowView = 1 << 0,
    AllowCreate = 1 << 1,
    AllowChange = 1 << 2,
    AllowFilter = 1 << 4,
    AllowSort = 1 << 8,
}

would transform that code

class Person
{
    [Attr(Capabilities = AttrCapabilities.AllowChange | AttrCapabilities.AllowFilter | AttrCapabilities.AllowView)]
    public string? FirstName { get; set; }
}

to

class Person
{
    [Attr(Capabilities =  AttrCapabilities.AllowView | AttrCapabilities.AllowChange | AttrCapabilities.AllowFilter)]
    public string? FirstName { get; set; }
}

My use-case is that all properties of my domain objects are marked with these flags and it would help visually scanning them if they were sorted.

@sharwell
Copy link
Member

sharwell commented Feb 7, 2024

I believe this rule would be better implemented in a separate analyzer project.

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

2 participants