GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — use enum name in repr by koubaa · Pull Request #2239 · pythonnet/pythonnet Conversation
|
|
Can you please make the format similar to Python's >>> 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 P.S. Disregard the Mac and ARM failures, they are caused by our test infra. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@lostmsu Done - but I'm not really that happy with the Flags case. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@koubaa both of course. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
mirror of upstream PR: pythonnet/pythonnet#2239
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Enum __repr__ string could be improved
There was an error while loading. Please reload this page.