-
C# 12 features: Interceptors
Part 8 in a series on new language features in C# 12.
Interceptors
This is an experimental feature that is disabled by default. It is an enhancement that source generators will be able to take advantage of. It allows source generators to modify (replace) existing code, rather than just adding new code.
Being an experimental feature, the implementation details are likely to change over time, and there's no guarantee that it will necessarily ship as a regular feature in the future.
Further reading
https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md
Example source
https://github.com/flcdrg/csharp-12/tree/main/08-interceptors
-
C# 12 features: ExperimentalAttribute
Part 7 in a series on new language features in C# 12.
Experimental attribute
Mark a type, method, or assembly with the
ExperimentalAttribute
and the compiler will generate a warning. You will need to explicitly suppress this warning to consume the experimental code.[Experimental("DAVID01")] public class ExperimentalClass { public void Thing() { // } }
In some ways, this feels to me like the opposite of the
ObsoleteAttribute
.Further reading
Example source
https://github.com/flcdrg/csharp-12/blob/main/07-experimental/ExperimentalClass.cs
-
C# 12 features: Inline arrays
Part 6 in a series on new language features in C# 12.
Inline arrays
Super-niche, but I guess if you need it, you'll appreciate it. Previously you'd probably need to resort to using
unsafe
code to deal with this.[System.Runtime.CompilerServices.InlineArray(10)] public struct InlineArray { public int Thing; }
The compiler now knows this is an array of 10 contiguous elements.
Further reading
Example source
https://github.com/flcdrg/csharp-12/blob/main/06-inline-arrays/InlineArrays.cs