| |

NET 8 – Include non-public members in JSON serialization

Starting with .NET 8 you can include non public properties in the serialization when using System.Text.Json. To do so, simply decorate the non-public property with the JsonIncludeAttribute attribute. The attribute works with any non-public modifier, such as private, protected or internal. Let’s look at an example: As expected, this will output the following:

The syntax for declaring an InlineArray in C# 12.

C# 12 – Inline arrays

Inline arrays enable you to create an array of fixed size in a struct type. Such a struct, with an inline buffer, should provide performance comparable to an unsafe fixed size buffer. Inline arrays are mosly to be used by the runtime team and some library authors to improve performance in certain scenarios. You likely…

An example of a tuple alias, introduced in C# 12

C# 12 – Alias any type

The using alias directive has been relaxed in C# 12 to allow aliasing any sort of type, not just named types. This means that you can now alias tuples, pointers, array types, generic types, etc. So instead of using the full structural form of a tuple, you can now alias it with a short descriptive…

What’s new in C# 12

As technology continues to evolve, so does the C# programming language. With the release of C# 12 on the horizon, developers can look forward to a host of exciting new features and enhancements that promise to streamline their coding experience and open up new possibilities in software development. If you haven’t yet switched to C#…

How to switch to C# 12

While trying out C# 12 features, it’s possible you might come across errors similar to these: Feature is not available in C# 11.0. Please use language version 12.0 or later. or Error CS8652: The feature ‘<feature name>’ is currently in Preview and unsupported. To use Preview features, use the ‘preview’ language version. There are two…