Coding C# with C#
summary
Shows a working Roslyn Analyzer that scans controller methods and emits diagnostics when endpoints lack Authorize or AllowAnonymous attributes, implemented as a DiagnosticAnalyzer and covered by unit tests. Demonstrates a Source Generator that generates interfaces for mocking at compile time (in-memory, not on disk), with generated code verified by brittle string-equality tests. Notes: projects must target .NET Standard 2.0, parsing works on source strings, performance and debugging are nontrivial but the tools do produce usable results.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 0:47Welcome and Resources
- 2:10Automating Checks, Not Just Code
- 5:13A Short History of the C# Compiler and Roslyn
- 8:50Roslyn Analyzers
- 10:05Example Analyzer: Required Attributes on Controller Endpoints
- 11:51Building an Analyzer Project
- 17:07Unit Testing Analyzers
- 17:40Roslyn Source Generators
- 20:02Example: Generating Interfaces for Mocking
- 24:14Testing Source Generators
- 25:46Q&A
