Skip to content

GenAPI formatting of enums #44999

Open
Open
@PranavSenthilnathan

Description

@PranavSenthilnathan

GenAPI can emit enum member values in hex or left-shift formats if the enum has FlagsAttribute. For example, see CompareOptions. While the generated file isn't designed for readability, it does make it easier to review.

Actual:

[System.FlagsAttribute]
public enum CompareOptions
{
    None = 0,
    IgnoreCase = 1,
    IgnoreNonSpace = 2,
    IgnoreSymbols = 4,
    IgnoreKanaType = 8,
    IgnoreWidth = 16,
    OrdinalIgnoreCase = 268435456,
    StringSort = 536870912,
    Ordinal = 1073741824,
}

Expected:

[System.FlagsAttribute]
public enum CompareOptions
{
    None = 0,
    IgnoreCase = 1 << 0,
    IgnoreNonSpace = 1 << 1,
    IgnoreSymbols = 1 << 2,
    IgnoreKanaType = 1 << 3,
    IgnoreWidth = 1 << 4,
    OrdinalIgnoreCase = 1 << 28,
    StringSort = 1 << 29,
    Ordinal = 1 << 30,
}

or

[System.FlagsAttribute]
public enum CompareOptions
{
    None = 0x00000000,
    IgnoreCase = 0x00000001,
    IgnoreNonSpace = 0x00000002,
    IgnoreSymbols = 0x00000004,
    IgnoreKanaType = 0x00000008,
    IgnoreWidth = 0x00000010,
    OrdinalIgnoreCase = 0x10000000,
    StringSort = 0x20000000,
    Ordinal = 0x40000000,
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions