Giter Club home page Giter Club logo

csharp-source-generators's Introduction

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

  • AnyOf - stars last commit https://github.com/nemesissoft/Nemesis.TextParsers) The Source Generator creates a AnyOf<First, TSecond, ...> type to handle multiple defined types as input parameters for methods.
  • AutoDeconstructable - stars last commit Generator for efficient and automatic flat text serializer/deserializer using Deconstructable aspect in NTP library.
  • AutoInterface - stars last commit interface-to-member source generator.
  • Avalonia.NameGenerator - stars last commit Generates typed references to named Avalonia XAML controls.
  • avatar - stars last commit A modern compile-time generated interception/proxy library.
  • Azura - stars last commit Generates binary [de]serializers on Streams at design time.
  • boilerplatezero - stars last commit WPF Dependency Property Generator.
  • Cloneable - stars last commit auto-generate Clone method.
  • CrossLink - stars last commit A C# Library for creating and managing multiple links between objects.
  • Data Builder Generator - stars last commit Generate data builder patterns for your model classes.
  • DevExpress.Mvvm.CodeGenerators - stars last commit Generates boilerplate code for your View Models (INotifyPropertyChanged, Commands, IDataErrorInfo, DevExpress services).
  • dotVariant - stars last commit A type-safe and space-efficient sum type for C# (comparable to discriminated unions in C or C++).
  • Durian - stars last commit Extends the default capabilities of C# by mimicking features from other languages.
  • EnumFastToStringDotNet - stars last commit - Automatically generates enum extension methods that implement a switch expression based ToString method.
  • Fairy - stars last commit generates C# code based on Sitecore Content Serialization (SCS) .yml files.
  • Flattening - stars last commit - C# source generator for generating flattened classes from complex domain classes.
  • FluentBuilder - stars last commit - A project which uses Source Generation to create a FluentBuilder for a specified model or DTO.
  • Generator.Equals - stars last commit generates equality and hashing for classes and records, supports a number of strategies for comparing collections and properties.
  • GitBuildInfo.SourceGenerator - stars last commit - for dumping the git information (commit hash, branch, the head description) into assembly level metadata attributes.
  • HttpClientCodeGenerator - stars last commit - HttpClientGenerator is a tool that uses the Roslyn code generator feature to write boilerplate HttpClient code for you.
  • IDisposableGenerator - stars last commit - a Source Generator for Generating the Dispose functions in Disposables. All you have to do is mark them with attributes and it will work from there.
  • Imp.NET - stars last commit - a fast, high-level, object-oriented C# networking library that supports the invocation of remote methods through proxy interface objects.
  • IoTHubClientGenerator - stars last commit Build a C# Azure IoT Device client program in seconds!
  • Jab - stars last commit - Compile Time Dependency Injection
  • JsonByExampleGenerator - stars last commit - generate classes based on example json files in your project.
  • JsonSrcGen - stars last commit - compile time JSON serializer generation.
  • kli.Localize - stars last commit - localize strings from json files via source code generation
  • lambdajection - stars last commit Framework for building AWS Lambdas using dependency injection and aspect-oriented programming.
  • Lazysh - stars last commit Lazy implementation of any interface.
  • MapTo - stars last commit - A convention based object to object mapper similar to Automapper.
  • MemberAccessGenerator - stars last commit generates GetMember(int) and/or GetMember(string) methods that return property value for a given property name or index (e.g. in positional records).
  • MiniRazor - stars last commit Portable Razor compiler & code generator.
  • MockableStaticGenerator - stars last commit A C# source generator to make an interface and a class wrapper to test static/extension methods.
  • MockGen - stars last commit A C# mocking library based on source generators.
  • MockSourceGenerator - stars last commit A C# mocking library that generates mocks at compile-time using a source generator.
  • MrMeeseeks.ResXToViewModelGenerator - stars last commit Takes ResX files and generates localization ViewModels for a more convenient usage of localization in MVVM projects.
  • MrMeeseeks.StaticDelegateGenerator - stars last commit Maks static classes and members injectable as dependency by generating delegating interfaces and their implementing classes.
  • MvvmGen - stars last commit A lightweight MVVM library for XAML applications that generates your ViewModels with a C# Source Generator.
  • net_automatic_interface - stars last commit .Net Core Source Generator for Automatic Interfaces.
  • Plastic - stars last commit This project provides encapsulation of things like Domain, Application Rules, Business Rules or Business Logic in Application.
  • PrimaryConstructor - stars last commit Generate primary constructor from readonly fields.
  • PrimitiveStaticDataGenerator - stars last commit for creating methods that return optimized ReadOnlySpan<T> static data from primitive values.
  • PrintMembersGenerator - stars last commit helps re-defining C# record's PrintMembers method to force include/exclude certain members.
  • ProxyInterfaceGenerator - stars last commit 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.
  • Pure.DI - stars last commit - dependency injection for .NET without any IoC/DI containers, frameworks, dependencies, and thus without any performance impact and side-effects.
  • ResXFileCodeGenerator - stars last commit Generates strongly-typed resource classes for looking up localized strings.
  • ScenarioTests - stars last commit Test your code like you would write a notebook. Simply and effective
  • SerdeDn (serde-sn) - stars last commit is a port of the popular serde.rs Rust serialization/deserialization library to .NET. Basic cases are fully automated using a C# source generator.
  • SmallSharp - stars last commit Create, edit and run multiple C# 9.0 top-level programs in the same project by just selecting the startup program from the start button.
  • SmartAnnotations - stars last commit A library that uses source generators to automatically generate data annotations for your models. It provides a strongly-typed mechanism (fluent like API) to define your annotation rules.
  • SourceInject - stars last commit A source generator that allow you to generate your services for dependencies injection during compile time.
  • SpreadCheetah - stars last commit Create Excel files with a C# Source Generator for generating the rows.
  • SqlMarshal - stars last commit Native AOT friendly-performant mini-ORM. Generation of wrappers for accessing SQL using ADO.NET.
  • StackXML - stars last commit Stack based zero-allocation XML serializer and deserializer.
  • StringLiteralGenerator - stars last commit for optimizing UTF-8 binaries.
  • StrongInject - stars last commit - compile time dependency injection for .NET.
  • StructPacker - stars last commit binary serializer that auto-generates C# serialization code to achieve peak runtime performance and efficiency.
  • Svg to C# Source Generators - stars last commit 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.
  • ThisAssembly - stars last commit Exposes project and assembly level information as constants in the ThisAssembly class.
  • ToString - stars last commit - C# source generator for implementing ToString override like record type.
  • Transplator - stars last commit A simple C# source generator for text templates.
  • Tinyhand - stars last commit - Tiny and simple data format/serializer using a source generator.
  • ValueChangedGenerator - stars last commit for generating PropertyChanged from inner struct members.
  • ValueObjectGenerator - stars last commit C# source generator is for ValueObjects (ie.Wrapper classes).
  • WrapperValueObject - stars last commit - for creating simple value objects wrapping primitive types.

Tips & Tricks

Collection of tips and tricks (simple and brief to fit in Tweet):

Tweeted by @raboof on May 25 2021 at 23:00:

TIL to debug a source generator in VS 16.10: upgrade Microsoft.CodeAnalysis.CSharp to 3.10.*, add <IsRoslynComponent>true</IsRoslynComponent> to source generator project, select Roslyn Component for Launch in Project Properties Debug page, choose Target then F5 ๐Ÿš€

Source Generator debugger

Tweeted by @raboof on Nov 16 2020 at 20:57:

See files emitted by #SourceGenerators by adding these properties to your (*.csproj) project file:

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>

Tweeted by @Chiser99 on Sep 02 2020 at 06:41:

I made a thing: https://github.com/chsienki/Kittitas

If you're building Roslyn Source Generators or Analyzers check it out, it makes debugging them inside the compiler easier. #roslyn #csharp #dotnetcore #sourcegenerators #analyzers

Build failed in WPF projects microsoft/CsWin32#7:

If your build failed in a _wpftmp.csproj file you need to add following property to your (.csproj) project file:

<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>

and use at least .NET 5.0.102 SDK

Articles

Videos

Demo, PoC and excercise projects

Maybe they can inspire you too!

  • AutoCoder - stars last commit for effective and flexible object coding.
  • RyanAlameddine/SourceGeneratorDemo - stars last commit contains 3 demos: hello world, INPC and OpCode class.
  • TMC-CSharp/CodeExerciseLibrary - stars last commit Library to help creating C# exercises. Generates missing methods and classes inside tests on the fly by using Source Generators.
  • DpdtInject - stars last commit 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 - stars last commit contains 4 generators: AutoNotify, ConsoleWritelineHijack, HelloWorld and SettingsXml, plus nice presentation slides.
  • Compile Time Method Execution Generator - stars last commit proof of concept that allows executing a method during compilation, so that it can be really fast during runtime.

Projects using custom Source Generators "internally"

  • Elskom/Sdk - stars last commit Dumps git repository data to assembly level metadata attributes that can be checked at runtime for things like trapping if a user is using an possibly unstable build of the libraries built in the repository and so the user can see a message about it (and optionally opt into running the possibly unstable code).
  • NetFabric.Hyperlinq - stars last commit generates overloads for its extension methods.
  • RestEase - stars last commit uses Source Generator to generate interface implementations on compile time instead of in runtime via Reflection.Emit.
  • WarHub/wham - stars last commit generates code for immutable tree object graph based on red-green node approach used in Roslyn; generates custom XmlSerializer that supports C#9 records and ImmutableArray.

csharp-source-generators's People

Contributors

alexgoon avatar amis92 avatar arahaan avatar archi-doc avatar atifaziz avatar b1z0n avatar burgyn avatar diegofrata avatar douglasdwyer avatar fiseni avatar giggio avatar hamedfathi avatar ironcev avatar jalalx avatar kant2002 avatar koenbeuk avatar lucina avatar michalbrylka avatar mknejp avatar mrtaikandi avatar mrxx99 avatar ngbrown avatar pocki avatar ranma42 avatar sang-hyeon avatar spinnernicholas avatar stefh avatar worldbeater avatar ycanardeau avatar yeah69 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.