-
Notifications
You must be signed in to change notification settings - Fork 59
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
Conversation
? member.EqualsValue.Value.ToString() | ||
: null; | ||
|
||
if (value?.StartsWith("0b") == true) |
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Javascript do not have underline separating values.
C# accepts undescore in any type of number.
1c22985
to
a1e636e
Compare
Javascript do not have underline character separating values.