C# Source Generators
A list of C# Source Generators (not necessarily awesome), because I haven't found a good list yet.
C# Source Generators is a Roslyn compiler feature introduced in C#9/.NET 5. It lets C# developers inspect user code and generate new C# source files that can be added to a compilation.
Add GitHub topic
csharp-sourcegenerator to your generator repo - let's get it started!
Documentation and samples
- dotnet/roslyn feature design document describing the compiler feature.
- dotnet/roslyn cookbook to help with generator creation.
- dotnet/roslyn-sdk samples show how to implement a source generator and use features like external package references (inside generators).
- sourcegen.dev - an online Source Generator Playground to play with generator ideas
💡without any setup noise. Source repo.
- davidwengier/SourceGeneratorTemplate - A basic template for writing a C# source generator, from the Roslyn dev.
- Cloneable - auto-generate Clone method.
- JsonSrcGen - - compile time JSON serializer generation.
- MemberAccessGenerator - generates
GetMember(string)methods that return property value for a given property name or index (e.g. in positional records).
- net_automatic_interface - .Net Core Source Generator for Automatic Interfaces.
- PrintMembersGenerator - helps re-defining C# record's PrintMembers method to force include/exclude certain members.
- StringLiteralGenerator - for optimizing UTF-8 binaries.
- StrongInject - - compile time dependency injection for .NET.
- StructPacker - binary serializer that auto-generates C# serialization code to achieve peak runtime performance and efficiency.
- Svg to C# Source Generators - SVGC compiles SVG drawing markup to C# using SkiaSharp as rendering engine. SVGC can be also used as codegen for upcoming C# 9 Source Generator feature.
- How to Debug C# 9 Source Code Generators (2020-10-09)
- .NET Blog 'New C# Source Generator Samples' post (2020-08-25) that shows some simple samples.
- .NET Blog 'Introducing C# Source Generators' post (2020-04-29) that announces the feature.
- .NET Languages and Runtime Community Standup - Source Generators (2020-10-08) shows how Generators work and how they can be tested.
- Channel 9 'Source Generators in C#' (2020-08-12) has Roslyn PMs discussing the feature.
Demo, PoC and excercise projects
Maybe they can inspire you too!
- RyanAlameddine/SourceGeneratorDemo - contains 3 demos: hello world, INPC and OpCode class.
- TMC-CSharp/CodeExerciseLibrary - Library to help creating C# exercises. Generates missing methods and classes inside tests on the fly by using Source Generators.
- DpdtInject - DI container based on C# Source Generators. Its goal is to remove everything possible from runtime and make resolving process as faster as we can. This is achieved by transferring huge piece of resolving logic to the compilation stage into the source generator.
- jakubsturc/talk-csharp-source-generators - contains 4 generators: AutoNotify, ConsoleWritelineHijack, HelloWorld and SettingsXml, plus nice presentation slides.
- Compile Time Method Execution Generator - proof of concept that allows executing a method during compilation, so that it can be really fast during runtime.