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

Validate enum binary value #75

Merged
merged 2 commits into from
May 28, 2024
Merged

Conversation

digocesar
Copy link
Collaborator

Javascript do not have underline character separating values.

@digocesar digocesar requested a review from SafeerH May 23, 2024 15:25
? member.EqualsValue.Value.ToString()
: null;

if (value?.StartsWith("0b") == true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numbers can have underscores in C# and it doesn't have to start with "0b".

For example:
This is a valid C# enum:

public enum A
{
    A = 1,              // decimal: 1
    B = 1_002,          // decimal: 1002
    C = 0b011,          // binary: 3 in decimal
    D = 0b_100,         // binary: 4 in decimal
    E = 0x005,          // hexadecimal: 5 in decimal
    F = 0x000_01a,      // hexadecimal: 26 in decimal
    G                   // 27 in decimal
}

And the acceptable/ideal TS output has to be:

export enum A {
    A = 1,
    B = 1002,
    C = 0b011,
    D = 0b100,
    E = 0x005,
    F = 0x00001a,
    G = 27 // I think, currently this will print as 6 (incorrect)
}

If we can do this; that would be the great. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, your suggestion is to always remove the undescore. Not only in binary. That's right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had updated code and tests to always remove undescore.
I had tested the sample case and all are working in TypeScript.
I think case "G" should be handled in another PR.

Copy link
Collaborator

@SafeerH SafeerH May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so, assuming the member.EqualsValue.Value is always a numerical value.
I tested this on my project too and it is working.

Rodrigo Cesar added 2 commits May 27, 2024 08:24
Javascript do not have underline separating values.
C# accepts undescore in any type of number.
@digocesar digocesar force-pushed the binary-enum-values branch from 1c22985 to a1e636e Compare May 27, 2024 11:50
@SafeerH SafeerH merged commit b9468d9 into svenheden:master May 28, 2024
@digocesar digocesar deleted the binary-enum-values branch May 28, 2024 16:04
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

Successfully merging this pull request may close these issues.

2 participants