source generator
A compiler plug-in that writes extra C# code during the build, based on the code you wrote.
In more detail
Generated code is compiled together with your code, so errors appear at build time. Mapperly and System.Text.Json use source generators to replace run-time reflection with ordinary compiled code that the compiler checks.
Related terms
- Roslyn — The open-source compiler for C# and Visual Basic, which turns source code into intermediate language inside an assembly.
- reflection — Code inspecting types, properties and methods at run time instead of knowing them at compile time.
- Mapperly — An open-source .NET library that generates object-mapping code at compile time from a partial class marked [Mapper].
- partial class — A class or method declared with partial so that its definition can be split across files, with some parts written by a tool.
Taught in
- Source-Generated Mapping with Mapperly — Modern .NET Core, C# & Enterprise Microservices