Enum types use enum value rather than enum name when converted to string
See original GitHub issueDescribe the bug in detail: In C#, when you use ToString() on an enum type, it will return the name of the enum value, while in U# it returns the integer converted to a string. This is undesirable behavior most of the time, and unaligned with C#'s behavior.
Provide steps/code to reproduce the bug: Let’s take this enum for instance:
public enum MyEnum {
MyFirstValue,
MySecondValue
}
If we print it out like this, we should see the problem:
MyEnum myEnumInstance = MyEnum.MyFirstValue;
Debug.Log(myEnumInstance.ToString());
Expected behavior: Log should read “MyFirstValue”
Observed behavior: Log actually reads “0”
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
Get Enum Name as String in TypeScript
No, you can't convert an enum name to a string as type information is stored only during compilation. You have to pass additional...
Read more >TypeScript string enums, and when and how to use them
No matter how much you know about TypeScript enums, this guide covers all the best practices for using string-based enums in production.
Read more >Best ways to convert an enum to a string
This article is a small list of ways to add reflection to enums. ... convert from and to strings and you can iterate...
Read more >TypeScript enums vs. types: Enhancing code readability
The obvious difference between numeric and string enums is that numeric enum values are mostly sequentially incremented automatically, while ...
Read more >String Enums in C#: Everything You Need to Know
The simplest way to convert enum values into string representation is by using a switch statement. Examples: C#. public string GetCountryName( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah that’s the plan to generate arrays, you can make a PR for it if you want it before I get around to it. If you do, note that enums with the Flags attribute generate their ToString() value differently from ones without it.
Only equality and inequality are handled for enums at the moment