Support C# 9.0 records
See original GitHub issueWith the advent of .NET 5.0 and C# 9 we now have a new, immutable-on-demand, kind of class with additional special features called record
. Would it be possible to add support for them (especially the type known as positional record) out-of-the-box?
Right now using them as if they were a normal class gives this exception:
public record SampleModel(string Name, int Age);
var sample = JsonSerializer.Generic.Utf8.Deserialize<SampleModel, ExcludeNullsCamelCaseResolver<byte>>(Encoding.UTF8.GetBytes(jsonString));
Positional records only have one public constructor:
var sample = new SampleModel("Name", 100);
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
What's new in C# 9.0 - C# Guide
C# 9.0 introduces record types. You use the record keyword to define a reference type that provides built-in functionality for encapsulating ...
Read more >Records in C# 9 - InfoQ
C# 9 introduces records, a new reference type for encapsulating data developers can use instead of classes and structs.
Read more >C# 9.0 - Introduction To Record Types
As we know in F#, everything is considered as immutable, and similarly in C# record types help us to work with immutable types....
Read more >How to work with record types in C# 9
A record type in C# 9 is a lightweight, immutable data type (or a lightweight class) that has read-only properties only. Because a...
Read more >Support for C# 9.0 in Visual Studio
When I try to use the new record keyword (or the init ), I get an unexpected token error in Visual Studio. What...
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 FreeTop 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
Top GitHub Comments
I published 3.1.0-rc1 to include the records stuff. It was a bit more complicated than expected, as records also support a mixed concept where not only those positional properties are used but additionally normal properties. SpanJson did not support that by now (as soon as you used the constructor attribute, it only used that and nothing else, other properties would be ignored). So I had to extend it for this functionality.
Yeah, I plan to add support for it in the next few days. I just haven’t looked into records much yet.