C# Source Generators – Why and How
In this recorded Live! 360 session, you’ll learn how C# source generators work, why they matter, and how they can dramatically improve app performance by eliminating runtime reflection, reducing allocations, and enabling ahead-of-time (AOT) execution. Jim Wooley walks through real examples, from logging and regex optimization to JSON serialization, and shows how incremental generators improve build performance and keep generated code in sync as you type. You’ll also explore how to write your own source generator using Roslyn APIs, understand syntax trees and semantic models, and validate generators with unit tests. If you're building .NET apps and want to automate boilerplate, remove reflection, or tune your app for speed, this session gives you the foundations to get started. 🔑 What You’ll Learn • What source generators are and how they fit into meta-programming • How generators eliminate reflection and support AOT compilation • Real examples: logging, regex, JSON, validation, mappers • How incremental generators improve performance over older models • How to explore Roslyn syntax trees & semantic models • How to write your own generator using attributes & visitors • Unit testing and debugging approaches for source generators • Performance impacts and comparisons (AutoMapper, Mapster, mocking libs) ⏱️ Chapters 00:00 Intro + What source generators are & why they exist 02:54 Eliminating reflection and enabling AOT 05:44 How source generators differ from GenAI 08:05 Examples in .NET: logging, regex, JSON, validation 11:58 Demo: Logging generator & partial methods 14:46 Demo: Regex generator & performance benefits 16:14 Demo: JSON serialization generator 17:40 Live change-tracking: how generators respond to edits 19:20 Using attributes to trigger generation 20:00 Intro to Roslyn syntax trees & code analysis 26:05 Navigating syntax with the Syntax Visualizer 29:32 Understanding attributes & metadata via Roslyn APIs 31:00 Demo: Building a simple CSV generator 35:55 Classic (non-incremental) generator architecture 38:30 Walking the syntax tree & extracting semantic info 41:52 Generating new code with StringBuilder 43:10 Incremental generators & why they matter 45:30 Transformations, caching, and performance optimization 47:25 Using records and value semantics in generator pipelines 49:00 Executing generation & adding output to the compilation 50:55 Demo: Extended CSV generator with new properties 54:00 How to test generators with xUnit & Verify snapshots 58:30 Debugging generators (best practices & pitfalls) 1:01:00 How Roslyn builds trees, tokens, trivia & factories 1:01:49 When meta-programming makes sense (mapping, DTOs, reflection removal) 1:03:00 Performance comparisons (AutoMapper, Mapster, mocking frameworks) 1:06:20 Licensing, open source considerations & practical guidance 1:08:48 Q&A + extending the sample generator 1:10:03 Additional resources & where to go next 👤 Speaker: Jim Wooley Senior Principal, Slalom Consulting 🔗 Links • Jim's Roslyn Labs repo: https://github.com/jwooley/RoslynLabs • Explore more Live! 360 sessions: https://aka.ms/L360Orlando25 • Check out upcoming VS Live! events: https://aka.ms/VSLiveEvents #csharp #dotnet #visualstudio #roslyn

Next-Level Debugging with GitHub Copilot in Visual Studio

What's New in C# | VS Live! Las Vegas 2026

Zero to Hero: Blazor Web Apps

Deep .NET: Writing async/await from scratch in C# with Stephen Toub and Scott Hanselman

Complete QA Guide in Azure DevOps | ADO Test Management for Beginners

How to Program Allen Bradley PLC Training for Beginners

Learn To See What God Sees When He Looks At You

The Frequency of God 963 Hz - Attract love, protection, wealth, miracles and blessings without limit

Union types in C# | DEM304

Welcome to .NET 10 & Visual Studio 2026!

Task vs ValueTask in C#

The Forgotten Features of Visual Studio You NEED In Your Life!

Visual Studio Toolbox Live: Working with Agent Skills

Best Practices in .NET I Don't Like Anymore

Honest Trailers | Idiocracy

Learn how to write better C# code in 15 minutes | DEM515

Replace Switch Statements with the Strategy Pattern in C#

My journey learning C++, part 53: Errors, Debugging part 2

Ed Zitron: Meta is making a $145bn mistake

