question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C# Compile Error When Using Negative Enum Values

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
johnxjchengcommented, Jan 8, 2019

@RSuter, I fixed the issue in the suggested location and created a pull request.

0reactions
RicoSutercommented, Jan 8, 2019

Merged and nswag updated, release soon

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found