All Projects → beakona → AutoInterface

beakona / AutoInterface

Licence: MIT license
C# interface-to-member source generator

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to AutoInterface

DpdtInject
Highly efficient compile-time general purpose DI container based on C# source generators.
Stars: ✭ 25 (-46.81%)
Mutual labels:  sourcegenerator, source-generators, csharp-sourcegenerator
Generator.Equals
A source code generator for automatically implementing IEquatable<T> using only attributes.
Stars: ✭ 49 (+4.26%)
Mutual labels:  source-generators, csharp-sourcegenerator
GitBuildInfo.SourceGenerator
Source Generator for dumping the git branch information, commit hash, and if the working tree is dirty or clean on projects that install this and applies them as an assembly level attribute.
Stars: ✭ 15 (-68.09%)
Mutual labels:  sourcegenerator, csharp-sourcegenerator
Tempy
Python Object Oriented Html Templating System
Stars: ✭ 126 (+168.09%)
Mutual labels:  templating
Blade
Use Blade templates without the full Laravel framework
Stars: ✭ 132 (+180.85%)
Mutual labels:  templating
Hyperscript
Create HyperText with JavaScript.
Stars: ✭ 2,312 (+4819.15%)
Mutual labels:  templating
TwistPHP
A fresh, new PHP MVC framework built from the ground up
Stars: ✭ 27 (-42.55%)
Mutual labels:  templating
Metalsmith Layouts
🌼 A metalsmith plugin for layouts
Stars: ✭ 109 (+131.91%)
Mutual labels:  templating
Pupa
Simple micro templating
Stars: ✭ 231 (+391.49%)
Mutual labels:  templating
Drone Gke
Drone plugin for deploying containers to Google Kubernetes Engine (GKE)
Stars: ✭ 159 (+238.3%)
Mutual labels:  templating
Mag.js
MagJS - Modular Application Glue
Stars: ✭ 157 (+234.04%)
Mutual labels:  templating
Mimic
mimic: Define your Deployments, Infrastructure and Configuration as a Go Code 🚀
Stars: ✭ 145 (+208.51%)
Mutual labels:  templating
Hermes
Golang package that generates clean, responsive HTML e-mails for sending transactional mail
Stars: ✭ 2,379 (+4961.7%)
Mutual labels:  templating
Jxls
Java library for creating Excel reports using Excel templates
Stars: ✭ 128 (+172.34%)
Mutual labels:  templating
Kontemplate
Extremely simple Kubernetes resource templates | Source has moved to https://git.tazj.in/tree/ops/kontemplate
Stars: ✭ 217 (+361.7%)
Mutual labels:  templating
Proji
A powerful cross-platform CLI project templating tool.
Stars: ✭ 156 (+231.91%)
Mutual labels:  templating
Genesis
Templating, scaffolding and generation tool
Stars: ✭ 122 (+159.57%)
Mutual labels:  templating
Phptal
PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages
Stars: ✭ 155 (+229.79%)
Mutual labels:  templating
Cruft
Allows you to maintain all the necessary cruft for packaging and building projects separate from the code you intentionally write. Built on-top of, and full compatible with, CookieCutter.
Stars: ✭ 180 (+282.98%)
Mutual labels:  templating
Meteor-Template-helpers
Template helpers for Session, logical operations and debug
Stars: ✭ 35 (-25.53%)
Mutual labels:  templating

AutoInterface

C# Source Generator which redirects all interface-calls to one or more backing members. Source code can be generated for a class, record, or struct. It can be generated automatically or by a custom template (scriban, liquid).

Manually written source:

interface IPrintable
{
   void Print();
}

public partial class Person : IPrintable
{
   [BeaKona.AutoInterface]
   private readonly IPrintable aspect1 = new PersonPrinterV1();
}

Auto-generated accompanying source:

partial class Person
{
   void IPrintable.Print() => this.aspect1.Print();
}

Ad-hoc adapter pattern

In this example PersonPrinterV1 does not implement IPrintable but does have all members that are required by that interface.

Manually written source:

interface IPrintable
{
   void Print();
}

class PersonPrinterV1
{
   void Print() { ... }
}

public partial class Person
{
   [BeaKona.AutoInterface(typeof(IPrintable))]
   private readonly PersonPrinterV1 aspect1 = new PersonPrinterV1();
}

Auto-generated accompanying source:

partial class Person : IPrintable
{
   void IPrintable.Print() => this.aspect1.Print();
}

Generate code from a template

Manually written source:

interface IPrintable
{
   void Print();
}

public partial class Person : IPrintable
{
   // add file mytemplate.scriban in your VS project
   // and set it's build action to: 'C# analyzer additional file'
   [BeaKona.AutoInterface(TemplateFileName = "mytemplate.scriban")]
   private readonly IPrintable? aspect1 = null;
}

Auto-generated accompanying source:

partial class Person
{
   ..generated from file..
}

Partial template

Partial template can be defined inline (from string) or from file.

Manually written source:

interface IPrintable
{
   int Length { get; }
   int Count { get; }
   void Print1();
   void Print2();
}

public partial class Person : IPrintable
{
   private void LogDebug(string name) { }

   [BeaKona.AutoInterface]
   [BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.PropertyGetter,
        Filter = "Length", Language = "scriban", Body = "return 1;")]
   [BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method,
        Filter = "Print(\\d)?", Body="LogDebug(nameof({{interface}}.{{name}})); {{expression}};")]
   private readonly IPrintable? aspect1 = new PrinterV1();
}

Auto-generated accompanying source:

partial class Person
{
   int IPrintable.Length
   {
      return 1;
   }
   
   int IPrintable.Count => this.aspect1!.Count;

   void IPrintable.Print1()
   {
       LogDebug(nameof(IPrintable.Print1));
       this.aspect1!.Print1();
   }

   void IPrintable.Print2()
   {
       LogDebug(nameof(IPrintable.Print2));
       this.aspect1!.Print2();
   }
}

Other examples can be found in wiki.


---

.NET Core NuGet

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].