M4rc0v0nh4g3n Authors Oleg Kyrylchuk
Retweets are appreciated 😊
#dotnet #csharp #coding #devcommunity
Constant interpolated
C# 10 allows initializing 'const' strings using string interpolation, but the placeholder must also be a 'const' string.
— Oleg Kyrylchuk (@okyrylchuk) September 9, 2021
The placeholder can't be a numeric constant cause it's converted to string at runtime.
Will you use the feature in your code?#dotnet #coding #devcommunity pic.twitter.com/H52ithdZC4
Extended property
Starting from C# 10, you can reference nested properties or fields within a proper pattern.
— Oleg Kyrylchuk (@okyrylchuk) September 10, 2021
The property pattern becomes more readable and requires fewer curly brackets \U0001f642
What do you think about the feature? #dotnet #coding #devcommunity pic.twitter.com/iHmbdYUAOW
File scoped
C# 10 introduces a new way of namespace declarations - file scoped namespaces.
— Oleg Kyrylchuk (@okyrylchuk) September 11, 2021
However, you cannot declare a nested namespace or a second file-scoped namespace in the same file.
C# continue to rid of curly brackets {\U0001f600}#dotnet #programming #devcommunity pic.twitter.com/docHOfZQYf
Global
C# 10 adds a new modifier to a 'using' directive - 'global'.
— Oleg Kyrylchuk (@okyrylchuk) September 12, 2021
It means that 'using' is applied to all files in the compilation.
All 'global using' directives must be before non-global 'using' directives.
It can be combined with a 'static' modifier#dotnet #coding #devcommunity pic.twitter.com/osr3ZPh5AI
Retweets are appreciated ☺️
#dotnet6 #coding #devcommunity #json #programming
Ignore circular
In .NET 5, you can preserve references for circular references using System.Text.Json.
— Oleg Kyrylchuk (@okyrylchuk) October 6, 2021
But you couldn't ignore them. The 'JsonException' is thrown if circular references have been detected.
In .NET 6, you can ignore them \U0001f642#dotnet6 #json #coding #devcommunity pic.twitter.com/FnvR8gjwvN
Notifications for
In .NET 6, System.Text.Json exposes notifications for (de)serialization.
— Oleg Kyrylchuk (@okyrylchuk) October 7, 2021
There are four new interfaces to implement according to your needs:
\u2022 IJsonOnDeserialized
\u2022 IJsonOnDeserializing
\u2022 IJsonOnSerialized
\u2022 IJsonOnSerializing#dotnet6 #json #coding #devcommunity pic.twitter.com/iYpzHsg8Hy
Serialization order of
In .NET 6, the 'JsonPropertyOrderAttribute' has been added to System.Text.Json.
— Oleg Kyrylchuk (@okyrylchuk) October 8, 2021
It allows controlling the serialization order of properties.
Previously, the serialization order was determined by reflection order.#dotnet6 #json #coding #devcommunity pic.twitter.com/5sBJRWOvcX
Write raw JSON with
.NET 6 introduces the possibility to write 'raw' #json with System.Text.Json.Utf8JsonWriter.
— Oleg Kyrylchuk (@okyrylchuk) October 16, 2021
Useful when you want:
\u2022 to enclose existing JSON in new JSON
\u2022 to format values differently from the default formatting#dotnet6 #coding #devcommunity pic.twitter.com/NguR3wEOAM