Let’s Build an Incremental Source Generator With Roslyn
summary
Live-coding builds an IIncrementalGenerator for Roslyn (targets .NET 6 / C# 10) that auto-generates partial IEqualityComparer implementations for specified types, emitting a marker attribute via post-initialization, using the syntax-provider predicate+semantic transform pipeline to extract type symbols. Tests run with Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit and mutation testing via Stryker.NET. Benchmarks show the generated comparer removes reflection for structs and yields zero allocation lookups; the incremental pipeline avoids regenerating unchanged files, improving IDE responsiveness.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 2:29Roslyn and Source Generators
- 9:05Source Generation rules
- 13:00ISourceGenerator to IncrementalGenerator
- 13:44Equality Comparer Generator
- 27:56IncrementalGenerator interface
- 33:28Incremental Pipeline
- 47:09Equality Comparer Code
- 51:28Testing and debugging
- 56:10Benefits of generated comparer
- 1:00:09Incremental generation power
- 1:04:59Source Generators best practices
- 1:06:25Q&A
related talks
01h 00mLet's Code an incremental source generator with Roslyn
01h 04mLet's Code 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
42mC# Code Generators: Writing Code That Writes Code
59mAutomating Observability With Roslyn Source Generators
50mImproving Source Code with Roslyn
