Session

Let's Build an incremental source generator with Roslyn

(Incremental) source generators allow us to trade in a bit of compile-time for better performance during run-time: Instead of resorting to general-purpose types and methods, we may utilize auto-generated variants optimized specifically for our user code. With these at our fingertips, we could facilitate high-performance scenarios by, for example, a Reflection-free source. If nothing else, this Roslyn-based metaprogramming relieves authors of writing repetitive patterns over and over again.

Source generators have been available since the .NET 5 SDK. Along with the introduction of incremental generators in the .NET 6 SDK, Microsoft has also started releasing generators and continued to do so with the .NET 7.0 and .NET 8.0 SDKs.

We will try some generators, from both NuGet and out of the box, to understand typical use cases. After examining their implementation to learn more about the programming model, we will build our very own incremental source generator, test-driven of course, and tool-assisted. As finishing touches we shall apply mutation testing and benchmarking before we deem our package almost ready for potential publication.

Experience with .NET/C# in general is required, but experience with Roslyn in particular is optional. An IDE such as Visual Studio (latest) or Rider (latest) is suggested, but using an editor, such as Visual Studio Code (latest C# extension), is also possible. Installation of the .NET 7.0 SDK (latest) is required.

Stefan Pölz

Clean C# Coder – Test-driven .NET Developer

Vienna, Austria

Actions

Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.

Jump to top