C Source Generators

Snapshot 2026-08-03 23:56:39 UTC · version 1

published
INDEXABLE MARKDOWN SNAPSHOT

Research document

Open canonical .md

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

Source Generators

Categories

Dependency Injection (IoC Container)

  • AutoCtor - AutoCtor is a Roslyn Source Generator that will automatically create a constructor for your class for use with constructor Dependency Injection.
  • AutoRegisterInject - Automatically generate Microsoft Dependency Injection ServiceCollection registrations for your classes from attributes.
  • CircleDI - The world only full-power circular Service Provider. It can resolve circular dependencies, has compile time safety and optimal performance.
  • DependencyInjection.SourceGenerators This project is a C# source generator designed to simplify and automate the registration of dependencies in Microsoft's Dependency Injection service collection. By using this package, developers can enhance the clarity and efficiency of their code by reducing the need for manual service registration.
  • DependencyManagement - The Dependency Management is a very fast dependency injection and components container, with many interesting features, and without reflection.
  • GrpcInjection - - GrpcInjection is a tool that allow you to inject Services and Interceptor in time of compilation inside of GRPC Projects using C# source generator.
  • Immediate.Injections - - Source generated dependency injection registrations
  • Injectio - - Source generator that helps register discovered services in the dependency injection container
  • Jab - - Compile Time Dependency Injection
  • lambdajection - Framework for building AWS Lambdas using dependency injection and aspect-oriented programming.
  • MrMeeseeks.DIE - An unambigous, convenient, flexible and feature rich compile time dependency injection container.
  • Pure.DI - - dependency injection for .NET without any IoC/DI containers, frameworks, dependencies, and thus without any performance impact and side-effects.
  • ServiceScan.SourceGenerator - Type scanning source generator for Microsoft.Extensions.DependencyInjection services registrations inspired by Scrutor.
  • SourceDepend - Simply tag members with a [Dependency] attribute and those will be added to the constructor, saving you from manual coding the constructor.
  • SourceInject - A source generator that allow you to generate your services for dependencies injection during compile time.
  • StrongInject - - compile time dependency injection for .NET.
  • Thunderboltloc - One of the very first IoC frameworks for .Net that has no reflection.

Console / CLI

  • AutoSpectre - Generates a service for prompting and populating a class using the Spectre.Console library
  • ConsoleAppFramework - - Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
  • docopt.net - generates C# source code that parses command-line arguments into a strong-typed arguments class (also generated), given just the POSIX-style usage in plain text as part of the CLI. In other words, write the help message for your program and get the entire parser generated for free!
  • Figgle - - Generate ASCII banner text at compile time (or run time) using figlet fonts.

Mappers

  • AutoDto - - A source generator that generates DTO models from BL to avoid same BL and DTO models
  • Facet - A source generator that instantly scaffolds DTOs, ViewModels and typed LINQ projections.
  • Flattening - - C# source generator for generating flattened classes from complex domain classes.
  • GraphQL.Tools - - A GraphQL to C# compiler (code-generator) which turns your GraphQL schema into a set of C# classes, interfaces, and enums.
  • Mapperly - - A source generator for generating object mappings. Inspired by MapStruct.
  • MappingCloningExtensions - Generates extensions of objects for mapping and cloning using either attributes or fluent style. Also, supports deep copying and specfiying whether it can do a deep copy and the possibility of doing so safely.
  • Mapster - - A fast, fun and performant object to object Mapper. Has better performance and is more memorry efficient than Automapper. Besides code generation, supports also Fluent API.
  • MapTo - - A convention based object to object mapper similar to Automapper.
  • NextGenMapper - Easy-to-use mapper without configuration.
  • SourceMapper - - generates Mappers code based on attributes used on interfaces or abstract classes. It is inspired by Java MapStruct
  • SourceMapper - A source generator that creates extension methods for cloning and mapping.
  • Facet - A source generator that instantly scaffolds DTOs, ViewModels and typed LINQ projections.
  • FastCloner - A source generator for deep cloning of objects with automatic reflection-based fallback for types that cannot be cloned ahead of time.

Communication

  • CoreWCF - CoreWCF provides support of WCF server side code on .NET Core / .NET6. CoreWCF allows users to inject services into OperationContract implementation using a source generator to provide an OperationContract implementation that fits the expected ServiceContract. The supplied implementation fetch services from the DI container the same way the [FromServices] attribute works in ASP.NET core MVC Controllers. The source generator supports both a dedicated [Injected] attribute and the ASP.NET Core MVC [FromServices] attribute.
  • Imp.NET - - a fast, high-level, object-oriented C# networking library that supports the invocation of remote methods through proxy interface objects.
  • IoTHubClientGenerator - Build a C# Azure IoT Device client program in seconds!

Graphics / Drawing

  • ComputeSharp - A .NET library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders, which are transpiled from C# and precompiled at build-time using source generators.
  • 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.

Enums

  • BetterEnums - C# Enums with values and better performance as a source generator
  • Credfeto.Enumeration.Source.Generation - Enum to text generator for enums - generates strongly typed enums for all enums in the assembly, and using EnumText attribute for third party enums. Also includes an analyzer to ensure that all enum usages use the .GetName extension method rather than .ToString.
  • Enum.Source.Generator - A C# source generator to create an enumeration (enum) class from an enum type. With this package, you can work on enums very, very fast without using reflection.
  • EnumClass - Generate Kotlin's enum class from C# enum with additional features like Switch function (instead of switch statement). It also contains support libraries like generator for JsonConverter for generated classes
  • EnumerationClassGenerator - - A C# source generator to create an enumeration class from an enum type.
  • EnumFastToStringDotNet - - Automatically generates enum extension methods that implement a switch expression based ToString method.
  • EnumUtilities - - A source generator that creates extension methods and utilities for enums with flags support, atomic operations (InterlockedAdd, InterlockedOr, etc.), and JSON converter generation.
  • EnumUtilitiesGenerator - - A source generator to generate compile-time mapping of enums and description attributes.
  • FastEnumGenerator - An enum like generator where you create a partial class with private enum and it will generate an enum like record struct even including returning the words and a list.
  • JOS.Enumeration - Enumeration class powered by source generation
  • NetEscapades.EnumGenerators - A source generator for generating fast "reflection" methods for enums
  • RapidEnum - - RapidEnum is a Source Generator that provides fast-running enum utilities for C#/.NET. It is faster than the .NET API and achieves zero allocation for all methods.

Functional Programming

Value semantic / New Type Idiom

  • ComparisonOperatorsGenerator - A Source Generator package that generates the >, >=, <, <= operators for a partial type (class, struct or record) which implements IComparable<T>.
  • Generator.Equals - generates equality and hashing for classes and records, supports a number of strategies for comparing collections and properties.
  • RSCG_UtilityTypes - Add Omit and Pick attributes to generate classes from existing class, like in TypeScript.
  • Strongly - Easily generate serializable domain value types
  • StronglyTypedId - A Rosyln-powered generator for strongly-typed IDs
  • ValueObjectGenerator - C# source generator is for ValueObjects (ie.Wrapper classes).
  • Vogen - C# source generator and code analyser that generates strongly typed domain identities.
  • WrapperValueObject - - for creating simple value objects wrapping primitive types.

Immutability

Discriminated Unions

  • AnyOf - The Source Generator creates a AnyOf<First, TSecond, ...> type to handle multiple defined types as input parameters for methods.
  • dotVariant - A type-safe and space-efficient sum type for C# (comparable to discriminated unions in C or C++).
  • Dunet - A simple source generator for discriminated unions in C#.
  • Funcky Discriminated Unions - A source generator that generates Match methods for all your discriminated unions needs. ✨ Can be used with or without the functional programming library Funcky.
  • MatchGenerator - Bring exhaustive pattern matching to C# enums and unions with zero boilerplate.
  • N.SourceGenerators.UnionTypes - Discriminated union type source generator.
  • Unions - for generating meaningful, efficient union types.

Serialization

  • AutoDeconstructable - Generator for efficient and automatic flat text serializer/deserializer using Deconstructable aspect in NTP library.
  • Azura - Generates binary [de]serializers on Streams at design time.
  • Csv-CSharp - - Csv-CSharp is a highly performant CSV (TSV) parser for .NET and Unity. It is designed to parse UTF-8 binaries directly and leverage Source Generators to enable serialization/deserialization between CSV (TSV) and object arrays with zero (or very low) allocation.
  • CSV-Parser-Generator - A Parser for CSV with support for uncommon line separators (e.g. Unicode) and instantiation of read-only objects and working nullable handling.
  • GenPack - is a library that uses the .NET source generator to automatically generate packets as classes once you define a schema for the packets. It's easy to use and the results are useful.
  • MemoryPack - - Zero encoding extreme performance binary serializer for C# and Unity.
  • MessagePack for C# - - Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity, Xamarin). / msgpack.org[C#]
  • ProtobufSourceGenerator - - A source generator that generates partial helper classes where member properties are attributed with ProtoMember attribute.
  • protobuf-net - - protobuf-net is a contract based serializer for .NET code, that happens to write data in the "protocol buffers" serialization format engineered by Google.
  • SerdeDn (serde-sn) - is a port of the popular serde.rs Rust serialization/deserialization library to .NET. Basic cases are fully automated using a C# source generator.
  • SpreadCheetah - Create Excel files with a C# Source Generator for generating the rows.
  • StackXML - Stack based zero-allocation XML serializer and deserializer.
  • StructPacker - binary serializer that auto-generates C# serialization code to achieve peak runtime performance and efficiency.
  • Tinyhand - - Tiny and simple data format/serializer using a source generator.
  • VYaml - - VYaml is a pure C# YAML 1.2 implementation, which is extra fast, low memory footprint with focued on .NET and Unity.

Json

  • GeneratedJsonConverters - - generate json converters for polymorph contracts and string based enum serialization.
  • JsonByExampleGenerator - - generate classes based on example json files in your project.
  • JsonDeserializeResourceSourceGenerator - Instead of having to do embedded resource, can instead have json as additional file and it will produce a c# string and will deserialize to a type specified.
  • JsonPolymorphicGenerator - - Source Code Generator for System.Text.Json JsonDerivedType attributes on polymorphic classes
  • JsonSerializerContextGenerator - A source generator that produces nearly the same code as system.json.text but easier to use because you only have to put an attribute for a model class you want to produce for. Also, produces a method to register to make it easy to use that source generator when serializing/deserializing json.
  • JsonSrcGen - - compile time JSON serializer generation.
  • TeuJson - A Reflection-less and Lightweight Json Library using source generator.

Caching

Validation

  • EasyValidate - - High-performance, type-safe .NET source generator that uses attributes to automatically generate validation for properties, fields, and method parameters. Easy Validate supports async validation, integrates with dependency injection, and includes rich analyzers and code fixers for a seamless developer experience.
  • Immediate.Validations - - Source generated validations for easy integration with Immediate.Handlers
  • Validly - - A performant, zero-allocation, and highly customizable validation library that generates validation logic based on attributes, with usage similar to DataAnnotations.

Localization

  • kli.Localize - - localize strings from json files via source code generation
  • MrMeeseeks.ResXToViewModelGenerator - Takes ResX files and generates localization ViewModels for a more convenient usage of localization in MVVM projects.
  • ResXGenerator - Generates strongly-typed resource classes for looking up localized strings.

Testing

  • Buildenator - Generate data builder classes for testing purposes (and not only) for your entities. Autofixture + Moq extensions.
  • FluentAssertions.Eventual - - Generates a specialized waiting wrapper for FluentAssertions assertions, offering a syntax similar to plain FluentAssertions.
  • ScenarioTests - Test your code like you would write a notebook. Simply and effective

Mocking

  • Forged - A fake data generation library that respects and enforces required properties.
  • GRPC-Mock-Server - - A source generator for stubbing GRPC services.
  • InterfaceGenerator - - Auto generate interface definition by implementation, for when you need an abstraction for the sake of mocking.
  • KnockOff - Source-generated mocking library with a hybrid stub+mock design. Stubs are real classes you define once and reuse across your test project, with full mock capabilities (Return, Verify, When chains) built in.
  • MockableStaticGenerator - A C# source generator to make an interface and a class wrapper to test static/extension methods.
  • MockGen - A C# mocking library based on source generators.
  • MockSourceGenerator - A C# mocking library that generates mocks at compile-time using a source generator.
  • ProxyInterfaceGenerator - generate an interface and a Proxy class for classes. This makes it possible to wrap external classes which do not have an interface, in a Proxy class which makes it easier to Mock and use DI.
  • Rocks - A mocking library based on the Compiler APIs (Roslyn + Mocks).

Patterns

  • ActorSrcGen - Generates boilerplate to turn simple C# classes into TPL Dataflow compatible pipelines with robust and performant asynchronous and concurrent code.
  • InlineComposition - A source generator that merges the content of other classes into one class. A simple workaround for struct inheritance or multiple inheritance.
  • JinShil.MixinSourceGenerator - A simple, but powerful source generator that implements the mixin design pattern by copying members—along with their attributes and XML documentation comments—verbatim from one or more source classes/structs into anaother, forming a composition of said classes/structs.
  • Lombok.NET - Generates boilerplate code and common code patterns. As the name suggests, it is the .NET version of Java's Lombok.
  • Minerals.AutoMixins - Package for automatic mixin design pattern generation using an incremental source generator.
  • Minerals.AutoCQRS - NuGet package that provides interfaces for implementing the CQRS pattern (Commands, Queries, and Pipelines) along with automatic dependency injection and no MediatR package overhead.

Mediator

  • DumplingsDevs.Pipelines - The most flexible mediation implementation in the .NET ecosystem with your own types.
  • Foundatio Mediator - - Blazingly fast, convention-based C# mediator powered by source generators and interceptors.
  • Immediate.Handlers - The fastest source generator implementation of the Mediator pattern in .NET, without using a central mediator instance.
  • Mediator - - a high performance implementation of Mediator pattern in .NET using source generators.
  • MediatR controllers generator - This generator generates controllers and their methods based on your MediatR requests.

Command

  • Plastic - This project provides encapsulation of things like Domain, Application Rules, Business Rules or Business Logic in Application.

Builder

Proxy

  • avatar - A modern compile-time generated interception/proxy library.
  • DudNet - A C# source generator for implementing a proxy pattern.

Visitor

  • MrMeeseeks.Visitor - Generates the boilerplate code for applications of the Visitor pattern.
  • Visitor.NET - First-ever acyclic generic extensible typesafe implementation of Visitor pattern for .NET without any usage of dynamic cast. Implementation powered by Source Generators

Adapter

This HTML preview is truncated for page performance. The canonical Markdown file contains the complete snapshot.

MARKDOWN METRICS
6240words
46headings
848links
2code blocks
MDRSS ASSESSMENT
Evidence46/100high confidence
Why MDRSS assigned this score
  • Production catalog audit 2026-08-04
  • Taxonomy classified from title, annotation, source and Markdown signals
  • Agent usefulness evaluated from structure, procedures, examples, evidence and retrieval value
Evidence (1)

Discussion 0

Sign in to join the discussion.