| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Can you please make the format similar to Python's enum.Enum: >>> from enum import Enum
>>> class Color(Enum):
... RED = 1
... GREEN = 2
...
>>> repr(Color.GREEN)
'<Color.GREEN: 2>'I suggest to use decimal values when enum is a regular enum, and either binary or hexadecimal when it has [Flags]. P.S. Disregard the Mac and ARM failures, they are caused by our test infra. |
Sorry, something went wrong.
|
@lostmsu Done - but I'm not really that happy with the Flags case. ToString() seems to make some choices about how to represent the value. Do you mean to only show the hex value if its Flags, instead of trying to show both integer and name? |
Sorry, something went wrong.
|
@lostmsu done. The switch case isn't so pretty, but I couldn't think of a way to improve it. here's a minimal compiler explorer link with that logic if anyone wants to try and see if they can improve it: https://godbolt.org/z/dYG6sdnKo |
Sorry, something went wrong.
|
@koubaa try using Convert.ChangeType string ConvertFlags(Enum value) {
Type primitiveType = value.GetType().GetEnumUnderlyingType();
string format = "X" + (Marshal.SizeOf(primitiveType) * 2).ToString(CultureInfo.InvariantCulture);
var primitive = (IFormattable)Convert.ChangeType(value, primitiveType);
return primitive.ToString(format, null);
}
string ConvertValue(Enum value) {
Type primitiveType = value.GetType().GetEnumUnderlyingType();
return Convert.ChangeType(value, primitiveType).ToString()!;
} |
Sorry, something went wrong.
mirror of upstream PR: pythonnet/pythonnet#2239
| Back | FazBrowse Home | New Git URL |
What does this implement/fix? Explain your changes.
Proposal to fix #2238
Before the changes:
IronPython (as a reference):
With these changes:
Checklist