Let's Code an incremental source generator with Roslyn
summary
Live codes an incremental Roslyn source generator that emits enum IsDefined methods as compile-time partial methods, using .NET 6 incremental APIs and post‑initialization to inject a marker attribute. Pipeline uses the SyntaxProvider .ForAttributeWithMetadataName and produces a single hint file via Source generator produces partial methods. Benchmarks with BenchmarkDotNet show the generated code matches a hand‑written fast check (~15 ns) and avoids runtime allocations. The pipeline uses collect + comparer for caching so unchanged inputs skip regeneration. Tools shown: Roslyn, Sharlab, Rider/Visual Studio, BenchmarkDotNet.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 2:33Roslyn and extensibility
- 10:04Source generator use cases
- 15:24Roslyn versioning
- 17:32Setup incremental generator
- 23:32IIncrementalGenerator
- 30:15Generation attribute
- 33:07Syntax and semantic analysis
- 41:55Incremental pipeline
- 47:18Source code output
- 55:09Incrementality for performance
- 59:31Q&A
related talks
01h 15mLet’s Build an Incremental Source Generator With Roslyn
01h 02mRoslyn Source Generators Never send a human to do a machine's job
54mExploring Source Generators
01h 12mC# Source Generators in Action
59mSource generators v2.0 — Incremental Generators
50mImproving Source Code with Roslyn
42mC# Code Generators: Writing Code That Writes Code
01h 08mAnalyzing source code using Roslyn
