Skip to content

Unable to compile CSharp code with models containing reserved keywords #31

@ragi-dayananda

Description

@ragi-dayananda

Context

The generated C# code cannot be compiled when models contain any reserved .NET keywords.
Eg, 'fixed', 'void', 'event', 'virtual' etc.. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/

enum invoice_amount_type {
   o fixed
   o maximum
}

enum issuing_card_type {
   o physical
   o virtual
}

enum invoice_status {
   o deleted
   o draft
   o open
   o paid
   o uncollectible
   o void
}

Expected Behavior

Any generated csharp code should be compilable.

Possible Fix

We can add a trailing underscore char to the reserved keyword.

Steps to Reproduce

Generate cshar code for any of the model provided in the above example. Add the generated models to any csharp project and try t build the project.

Your Environment

  • Version used: 3.11.1
  • Operating System and version (desktop or mobile): windows 11 desktop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions