Skip to content
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

Enable support for C# 9.0 records #1419

Merged
merged 3 commits into from
Oct 25, 2021

Conversation

MaxWilson
Copy link
Contributor

[Apologies in advance if I should have submitted an issue or something instead of just a PR out of the blue.]

This PR, in conjunction with a separate PR to NSwag, adds an option to change how ClassStyle="Record" generates DTOs. If you set "classStyle": "Record" and also "UseNativeRecords": true, nswag will generate DTOs as records instead of classes.

This allows you to use C# 9.0 "with" statements for usability, while still maintaining null safety.

@MaxWilson
Copy link
Contributor Author

I want to call out that in order to make the unit tests work, I had to upgrade the Microsoft.CodeAnalysis.CSharp dependency from 3.8.0 to 3.11.0, which is not compatible with .NET 4.5.2. I had to remove .NET 4.5.2 as a target framework for NJsonSchema.CodeGeneration.CSharp.Tests. I think this is a reasonable thing to do since it's test code, and doesn't impact NSwag/NJsonSchema's ability to generate .NET 4.5.2 code, but I want to make sure there's no pushback.

Alternately, we could just not AssertCompile() in that unit test, but I think that's a worse solution.

@RicoSuter RicoSuter merged commit 3aef4ea into RicoSuter:master Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants