-
Notifications
You must be signed in to change notification settings - Fork 22
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
Unable to compile CSharp code with models containing reserved keywords #31
Comments
We've various escaping functions implemented for the different code gen target languages. It would be great to have a generic function that all targets could use that was configured with a list of reserved key words / identifier syntax so we can remove some of this duplication and improve quality. |
1 similar comment
We've various escaping functions implemented for the different code gen target languages. It would be great to have a generic function that all targets could use that was configured with a list of reserved key words / identifier syntax so we can remove some of this duplication and improve quality. |
Hey there @ragi-dayananda @dselman . Just looked through the csharpvisitor.js file and found that the suggested fix is already implemented. I think the model being used in the issue example has incorrect syntax. Models should include a namespace declaration at the beginning, which is absent in the example. On adding a namespace decalaration to the given model,
it compiles just fine. |
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/
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
The text was updated successfully, but these errors were encountered: