Code that writes code - .NET Source generators

Room 5
11:40 - 12:40
(UTC+02

Talk (60 min)

Wednesday 
Tired of writing repetitive boilerplate code? Enter .NET Source Generators - your key to automating code generation at compile time. In this session, we'll explore and demystify this powerful feature that lets you inspect your codebase and generate new C# source files during compilation.
.NET

You'll learn how to create source generators from the ground up, including working with the Roslyn compiler API to analyze syntax trees, semantic models, and symbols. Don't worry, it's actually easier than it sounds! We'll explore practical techniques for traversing your codebase, filtering syntax nodes, and generating precise, context-aware code that integrates seamlessly with your existing projects.

Through hands-on examples, we'll implement source generators that solve real-world problems. We'll cover examples like creating strongly typed entity IDs to prevent primitive obsession, generating boilerplate code, auto-implementing interfaces, building compile-time helpers and more.

This session is designed for intermediate to advanced .NET developers, team leads and architects looking to improve code maintainability, as well as anyone interested in meta-programming and code generation.

After this session, attendees will gain a thorough understanding of source generator architecture and lifecycle, along with practical knowledge of working with the Roslyn API for code analysis. They'll learn essential techniques for debugging and testing source generators, good practices for implementing them in production projects, and acquire a toolkit of ready-to-use patterns for some common source generation scenarios.

Glenn F. Henriksen

Glenn F. Henriksen is a mentor and developer from Norway. As the co-founder and CTO of Justify, he gets to build new legal tools for everyone to use, helping to create better communication and less conflict in relationships. He's continuously exploring new tools, processes and technologies, and improving how he and his fellow developers work with code, tasks and projects. He has been a Microsoft Development MVP, a part of the Microsoft Regional Director program and is an ASP.NET Insider and an Azure Advisor. In the past 25+ years he has co-owned two companies, worked as a consultant, manager, support tech, network admin, developer, architect, technical lead and more, but his favorite things are still swapping code for food and building stuff that makes a difference in people’s lives.