Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum : short crashes #53

Closed
GonziHere opened this issue May 2, 2019 · 3 comments
Closed

enum : short crashes #53

GonziHere opened this issue May 2, 2019 · 3 comments

Comments

@GonziHere
Copy link

GonziHere commented May 2, 2019

public enum MyEnum: short{
            ValA= 1,
            ValB = 2,
}

It will crash in Generator.cs, in GetEnumValueText(object enumValue, Type type) on line var enumValueInt = (int)enumValue; because that is invalid cast (note that enumValueInt= (int)(short)enumValue would work).
Could this be fixed, and is there some way to disable enum generation in the meantime? I would be fine with numbers instead of all enums.

@jburzynski
Copy link
Owner

Hi, thanks for reporting the issue!

I'm on holiday now; I should be able to fix it on the weekend or the beginning of next week.

In the meantime, the solution could be to use TsTypeAttribute and TsDefaultValueAttribute on all properties/fields with enum values - this way you can e.g. set the type to number (this will also cause the enum types to not be generated) and the default value to a numeric value.

This can be time consuming if you have a lot of enum properties, but I can't think of another way of doing it unfortunately.

I'll post any updates on the progress in this thread.

@jburzynski
Copy link
Owner

Just a small update: there are some new things I'd like to add to the next release, so I will release the new version probably in a couple of days.

Right now there is a TypeGen NuGet package on the dev branch (in the nuget or nuget-dotnetcli folder) that contains the fix for the bug mentioned in this thread - the updated package should generate enums with all possible underlying types correctly.

Until the next version is released you can use this package locally, and of course I'll post an update here when I make the release.

@jburzynski
Copy link
Owner

I just released version 2.3.0, which should fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants