From Zero to Hero: Source Generators in C#

Master the art of writing code that writes code with source generators in C#

About This Course

Ever since Source Generators were added in C# and .NET, Microsoft has been consistently using them to improve the performance and flexibility of .NET and the BCL. Building source generators, however, is a mystery for many developers because it involves writing code that writes code. From AOT to mapping and much more, source generators can have thousands of use cases, and they are here to stay. If you want to never manually write a mapper again in your life but have the bad performance of a reflection-based mapper, learning how to use source generators will be an eye-opening experience for you. In this course, veteran developer Mel Grubb will assume you know nothing about source generators and teach you everything you need to know to start writing your own.

Course Curriculum

4h 11m 10 sections
Welcome
00:59 Free preview
What will you learn in this course?
00:37 Free preview
Who is the course for and prerequisites
01:28 Free preview
Overview
05:00
The Scenario
08:22
The Choices
03:29
Examples
07:41
Conclusion
01:30
Getting Started
06:19
Referencing the Generator
06:16
Generating Persistent Files
08:52
Conclusion
00:47
Overview
02:30
Debugging as a Roslyn Component
06:31
Conclusion
00:41
Overview
02:26
Generating the Marker Attribute
03:06
The Syntax Tree
04:39
The Predicate Method
02:39
The Transform Method
05:57
The Semantic Model
07:22
Testing ClassInfo
01:32
Conclusion
00:32
Overview
00:46
Generating the Partial Class
06:05
Refining the Generator
03:13
Generating the Properties
14:42
Conclusion
00:54
Overview
00:47
Validating Output
04:39
Snapshot Testing
10:42
Benchmarking the Generator
03:40
Conclusion
00:55
Overview
00:30
Fixing Bugs
03:56
Improving Performance
14:09
Accepting Parameters
06:44
Alternative Generation Pattern
04:58
Conclusion
01:52
Overview
01:36
Creating a NuGet Package
11:46
NuGet Package Contents
05:41
Publishing Locally
06:05
Publish to NuGet.org
04:50
Publishing From the Command Line
04:58
Publish From GitHub Actions
14:51
Conclusion
00:43
Overview
00:48
Targeting Multiple Types
06:19
Additional Files
09:09
Diagnostics
11:04
Limitations and Conclusion
05:38

Meet Your Instructor

Mel Grubb

Mel Grubb

Mel Grubb has been a professional software developer since 1995, working with .Net since version 1.0. Before that, he was a hobbyist since receiving his first computer, a TI-99/4a in 1982, and heavily modifying it over the course of several years. He's a software developer in central Ohio, concentrating on C# and ASP.Net MVC solutions with a focus on simplicity, testability, and overall coding craftsmanship.

View all courses by Mel Grubb

What's New

Deep Dive: Solution Architecture
course

Deep Dive: Solution Architecture

Master solution architecture and turn business needs into scalable, maintainable systems.

Learn More
Migrating: ASP.NET Web APIs to ASP.NET Core
course

Migrating: ASP.NET Web APIs to ASP.NET Core

A step-by-step process to migrate ASP.NET Web APIs from .NET Framework to ASP.NET Core.

Learn More
Getting Started: Caching in .NET
course

Getting Started: Caching in .NET

Let's make the hardest thing in programming easy for .NET software engineers.

Learn More
From Zero to Hero: Testing with xUnit in C#
course

From Zero to Hero: Testing with xUnit in C#

Learn how to test any codebase in .NET with the latest version of xUnit, the industry-standard testing library.

Learn More
Create a ChatGPT Console AI Chatbot in C#
blog

Create a ChatGPT Console AI Chatbot in C#

This walkthrough is your hands-on entry point to create a basic C# console application that talks to ChatGPT using the OpenAI API.

Learn More