elringus / bootsharp

Compile C# solution into single-file ES module with auto-generated JavaScript bindings and type definitions
https://sharp.elringus.com
MIT License
673 stars 36 forks source link

Improper generated enum values #129

Closed CADBIMDeveloper closed 11 months ago

CADBIMDeveloper commented 11 months ago

Hi @elringus ,

There is a problem with enum values handling in the bootsharp. Let's say, I have the following backend:

public enum Foo
{
    Value1 = 1,

    Value2 = 2
}

public static partial class Program
{
    public static void Main ()
    {
    }

    [JSInvokable]
    public static Foo Test() => Foo.Value1;
}

It generates the following definitions:

const Global = {
    ...
    test: () => deserialize(getExports().Program.Test()),
    Foo: { "0": "Value1", "1": "Value2", "Value1": 0, "Value2": 1 }
};

So

console.log(Global.test() === Global.Foo.Value1);

prints false

Thank you!

elringus commented 11 months ago

Yep, this is one of the breaking changes mentioned in #123.

426f29ee670e6a1ef62647adae767d8c

elringus commented 11 months ago

Ah, my bad, you're assigning custom enum indexes in C#. I'm probably hot handling that when generating JS enums. Will look into that, thanks for the report!