Let's Code an incremental source generator with Roslyn
summary
Live codes an IsEnumDefined generator that emits .g.cs methods from partial types using Microsoft.CodeAnalysis.CSharp.Workspaces and multi-targeted netstandard2.0 binaries, verifies behavior with Roslyn unit tests and mutation testing, and measures wins with benchmarks showing no boxing allocations and noticeably lower GC pressure for logging scenarios. Implementation uses an incremental pipeline with custom equality comparers to avoid full re-generation on whitespace edits, outputs auto-generated files and works under SDK 6.0.4+ with C# 11.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 2:30Roslyn and Source Generators
- 8:52Source Generator use cases
- 14:17Syntax trees and semantic models
- 22:24Building a generator step by step
- 33:53Incremental generator anatomy
- 41:34Incremental pipeline
- 51:21Code generation and debugging
- 53:12Performance pitfalls
- 57:36Best practices
- 58:37Resources
related talks
01h 15mLet’s Build an Incremental Source Generator With Roslyn
54mExploring Source Generators
01h 02mRoslyn Source Generators Never send a human to do a machine's job
01h 12mC# Source Generators in Action
01h 00mPattern-based C#: if it quacks like a duck…
50mThe Future of C#
50mAutomate Yourself Out Of a Job With Roslyn
59mAutomating Observability With Roslyn Source Generators
