UdonSharp
UdonSharp copied to clipboard
Enum types use enum value rather than enum name when converted to string
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"
This is known and will have partial handling eventually but can't have full handling due to boxing obscuring the user type.
Maybe add it to the "Differences from regular Unity C# to note" list at https://udonsharp.docs.vrchat.com/?
Currently I work around it by creating a string array containing the names of the enum values.
Unfortunately though the workaround splits these into two separate parts of the code, which is undesirable. Is it possible to just internally create this structure and any enum tostring just reference the name array for that enum?
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.
Speaking of enums using the flags attribute, it appears that operator | confuses the symbol processor on flags enums.
Only equality and inequality are handled for enums at the moment