dotnet / dotnet/sdk

GenAPI formatting of enums

Open
#44,999 0 comments 0 reactions 0 assignees View on GitHub
Area-GenAPI
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

GenAPI can emit enum member values in hex or left-shift formats if the enum has `FlagsAttribute`. For example, see [CompareOptions](https://github.com/dotnet/runtime/blob/3b91ac601980f3cc35e1d8687e7235e874ffc8ea/src/libraries/System.Runtime/ref/System.Runtime.cs#L9180-L9192). While the generated file isn't designed for readability, it does make it easier to review.

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

Expected:
```cs
[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

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.