question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum types use enum value rather than enum name when converted to string

See original GitHub issue

Describe 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:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
MerlinVRcommented, Oct 25, 2022

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.

0reactions
MerlinVRcommented, Oct 26, 2022

Only equality and inequality are handled for enums at the moment

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found