C# Compile Error When Using Negative Enum Values
See original GitHub issueWhen I input the following JSON with a negative enum value into NSwagStudio.
"dayoffRule": {
"format": "int32",
"description": "Day off rule for the shift. ScheduleData.Enums.ShiftDayOffRule",
"enum": [
0,
1,
3,
-1
],
"type": "integer"
},
I get the following invalid C#. Notice _1 is defined twice.
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "9.10.6.0 (Newtonsoft.Json v9.0.0.0)")]
public enum ShiftDayoffRule
{
_0 = 0,
_1 = 1, <<<
_3 = 3,
_1 = -1, <<<
}
Is there a workaround for this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
C/C++ Create an enum with negative values, without ...
If the first enumerator has no =, the value of its enumeration constant is 0. Each subsequent enumerator with no = defines its...
Read more >UENUM does not allow having negative values - C++
I want something like this: UENUM() enum Direction {BACKWARD = -1, STOP = 0, FORWARD = 1}; But when I compile I see...
Read more >Enums with negative value (-1) initialization
Hi,. Due to some reasons, I need to have the enum value start with -1. But, this is giving me compilation errors this...
Read more >Casting to Enum Gets Negative Value - C++ Forum
I'm having an issue when retrieving a numeric value from a message and attemping to cast it to the appropriate value in an...
Read more >V1016. The value is out of range of enum ...
The analyzer detected a dangerous cast from a numeric type to an enumeration. The specified number may not be in the range of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@RSuter, I fixed the issue in the suggested location and created a pull request.
Merged and nswag updated, release soon