> Markdown version of [/videos/192-c-9-source-generators-let-the-machine-do-the-programming?t=60](https://www.wearedevelopers.com/videos/192-c-9-source-generators-let-the-machine-do-the-programming?t=60). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # C# 9 Source Generators - let the machine do the programming Stop relying on slow runtime reflection and endless boilerplate. C# 9 Source Generators tap native compiler features to generate high-performance, strongly typed code on the fly. - **Speakers:** Jiří Činčura - **Event:** World Congress 2021 - **Published:** June 30, 2021 - **Duration:** 47:00 - **URL:** https://www.wearedevelopers.com/videos/192-c-9-source-generators-let-the-machine-do-the-programming ## Summary C# 9 Source Generators fundamentally change how developers handle boilerplate code by introducing robust metaprogramming directly into the build process. Instead of relying on computationally heavy runtime reflection or external pre-build scripts, developers can now tap into the compiler's abstract syntax trees to analyze code dynamically and inject new C# files on the fly. This architecture enables the creation of high-performance, ahead-of-time (AOT) friendly applications, zero-allocation parsers, and strongly typed interfaces mapped straight from external formats like CSV or Swagger. While these generators are intentionally constrained to strictly adding rather than modifying code, leveraging partial classes effortlessly circumvents this limitation to ensure a stable, predictable, and side-effect-free compilation pipeline. Automating notoriously verbose tasks, such as the INotifyPropertyChanged pattern, perfectly showcases how to "let the machine do the programming." By defining a syntax receiver, generators can efficiently filter down to applicable syntax nodes to radically minimize compile-time overhead compared to scanning an entire project tree. Furthermore, evaluating semantic models at build-time allows developers to construct heavily customized serializers without bleeding unnecessary metadata into the final application bundle. Successfully deploying these tools also requires thoughtfully managing dependencies; generator-specific processing logic must safely reside inside the NuGet distribution package, whereas the generated code's runtime constraints are explicitly left to the consumer environment. Ultimately, C# 9 Source Generators provide library authors and component vendors a remarkably fast, static, and strongly typed approach to solving traditionally slow, reflection-heavy development cycles. **Keywords:** c# 9 source generators, compiler metaprogramming, abstract syntax trees, partial classes implementation, semantic model inspection, syntax receiver pattern, inotifypropertychanged automation, zero-allocation parsing, aot compilation optimization, strongly-typed api integration, build-time static reflection, csv code generation, roslyn diagnostic reporting, nuget dependency scoping ## Chapters 1. **Overview of C# source generators and compilation pipeline** (01:00) — How meta programming allows code generation during the compiler evaluation phase. 1. **Common use cases for source code generation scenarios** (02:53) — Automating reflection, zero-allocation parsers, serializers, typed APIs, and AOT compilation environments. 1. **Current design constraints and compilation stability in generators** (09:05) — Why generators are restricted to adding code without explicit ordering or modification abilities. 1. **Implementing a basic hello world source generator module** (12:04) — Adding a simple static method by interacting with syntax trees and the execution context. 1. **Dynamic code generation from CSV data file definitions** (18:06) — Using additional files in the compiler context to automatically generate nested placeholder objects. 1. **Automating the property changed boilerplate GUI implementation pattern** (25:22) — Utilizing syntax receivers to track customized attributes and output automatic object state event bindings. 1. **Generating handcrafted high performance serializers for specific objects** (35:38) — Filtering semantic object member properties to produce fixed and rapid serialization procedures. 1. **Managing generator internal and consumer runtime dependency configurations** (41:18) — Separating libraries needed to run the generator from consumer compilation runtime dependencies. 1. **Reporting custom compiler diagnostics during the execution phase** (43:25) — Enhancing the developer experience by explicitly emitting contextual build warnings and compilation errors. 1. **Value proposition and compiler conclusions for library authors** (45:21) — How statically parsing semantic models heavily benefits component vendors through enhanced runtime profiles. ## Related Moments - [Understanding the basics of .NET source generators](https://www.wearedevelopers.com/videos/100154-code-that-writes-code-net-source-generators) (from "Code that writes code - .NET Source generators") - [Implementing a basic source generator pipeline](https://www.wearedevelopers.com/videos/100154-code-that-writes-code-net-source-generators) (from "Code that writes code - .NET Source generators") - [Abstractions and the push towards compiling natural language](https://www.wearedevelopers.com/videos/1909-wearedevelopers-live-back-to-code100) (from "WeAreDevelopers LIVE - Back to CODE100") - [Addressing iterative code generation and developer challenges](https://www.wearedevelopers.com/videos/1354-google-gemma-and-open-source-ai-models-clement-farabet) (from "Google Gemma and Open Source AI Models - Clement Farabet") - [Generating code structure clearly using partial properties](https://www.wearedevelopers.com/videos/1225-c-13-unleashed-live-demos-of-my-top-10-cutting-edge-features) (from "C# 13 Unleashed: Live Demos of my Top 10 Cutting-Edge Features!") - [Embracing code generation and modern editor evolution](https://www.wearedevelopers.com/videos/1403-five-things-in-tech-that-matter-and-we-have-to-make-work) (from "Five things in tech that matter and we have to make work") ## Related Articles - [Dev Digest 108 - Git off my cloud!](https://www.wearedevelopers.com/magazine/407-dev-digest-108-git-off-my-cloud) - [Liuba Gonta and Yuliya Khadasevic - GitHub Copilot Beyond the Basics - 10 Ways to Elevate Your Coding](https://www.wearedevelopers.com/magazine/490-liuba-gonta-and-yuliya-khadasevic-github-copilot-beyond-the-basics-10-ways-to-elevate-your-coding) - [How we Build The Software of Tomorrow](https://www.wearedevelopers.com/magazine/120-how-we-build-the-software-of-tomorrow) - [How to Use Generative AI to Accelerate Learning to Code](https://www.wearedevelopers.com/magazine/530-how-to-use-generative-ai-to-accelerate-learning-to-code) ## Related Jobs - [AI Software Engineer (Germany)](https://www.wearedevelopers.com/jobs/48317-ai-software-engineer-germany) at **Sunhat** - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Staff Software Engineer, Copilot Experiences](https://www.wearedevelopers.com/jobs/ext/164361-staff-software-engineer-copilot-experiences) at **GitHub** - [Senior Software Engineer,Billing](https://www.wearedevelopers.com/jobs/ext/1991843-senior-software-engineer-billing) at **GitHub** - [Senior Software Engineer, Enterprise Products](https://www.wearedevelopers.com/jobs/ext/1841248-senior-software-engineer-enterprise-products) at **GitHub** - [Principal Software Engineer, Enterprise AI Platform](https://www.wearedevelopers.com/jobs/ext/1467292-principal-software-engineer-enterprise-ai-platform) at **GitHub**