{"id":13629537,"url":"https://github.com/beakona/AutoInterface","last_synced_at":"2025-04-17T09:34:36.915Z","repository":{"id":37800403,"uuid":"309626696","full_name":"beakona/AutoInterface","owner":"beakona","description":"C# interface-to-member source generator","archived":false,"fork":false,"pushed_at":"2024-05-12T23:48:48.000Z","size":257,"stargazers_count":73,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-01T22:43:49.298Z","etag":null,"topics":["csharp","csharp-core","csharp-sourcegenerator","scriban","source-generators","sourcegenerator","templating"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beakona.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-03T08:52:06.000Z","updated_at":"2024-05-16T14:44:12.000Z","dependencies_parsed_at":"2024-03-19T23:29:34.122Z","dependency_job_id":"4757ec24-d11e-49ce-b4b4-1f0e8af4848c","html_url":"https://github.com/beakona/AutoInterface","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beakona%2FAutoInterface","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beakona%2FAutoInterface/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beakona%2FAutoInterface/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beakona%2FAutoInterface/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beakona","download_url":"https://codeload.github.com/beakona/AutoInterface/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751211,"owners_count":17196589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-core","csharp-sourcegenerator","scriban","source-generators","sourcegenerator","templating"],"created_at":"2024-08-01T22:01:13.112Z","updated_at":"2024-11-08T20:31:09.979Z","avatar_url":"https://github.com/beakona.png","language":"C#","readme":"# AutoInterface\n\nC# [Source Generator](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.md) 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](https://github.com/scriban/scriban), liquid).\n\u003cbr\u003e\n\nManually written source:\n\n```csharp\ninterface IPrintable\n{\n   void Print();\n}\n\npublic partial class Person : IPrintable\n{\n   [BeaKona.AutoInterface]\n   private readonly IPrintable aspect1 = new PersonPrinterV1();\n}\n```\n\nAuto-generated accompanying source:\n\n```csharp\npartial class Person\n{\n   void IPrintable.Print() =\u003e this.aspect1.Print();\n}\n```\n\u003cbr\u003e\n\n## Ad-hoc adapter pattern\n\nIn this example `PersonPrinterV1` does not implement `IPrintable` but does have all members that are required by that interface.\n\nManually written source:\n\n```csharp\ninterface IPrintable\n{\n   void Print();\n}\n\nclass PersonPrinterV1\n{\n   void Print() { ... }\n}\n\npublic partial class Person\n{\n   [BeaKona.AutoInterface(typeof(IPrintable))]\n   private readonly PersonPrinterV1 aspect1 = new PersonPrinterV1();\n}\n```\n\nAuto-generated accompanying source:\n\n```csharp\npartial class Person : IPrintable\n{\n   void IPrintable.Print() =\u003e this.aspect1.Print();\n}\n```\n\u003cbr\u003e\n\n## Generate code from a template\n\nManually written source:\n\n```csharp\ninterface IPrintable\n{\n   void Print();\n}\n\npublic partial class Person : IPrintable\n{\n   // add file mytemplate.scriban in your VS project\n   // and set it's build action to: 'C# analyzer additional file'\n   [BeaKona.AutoInterface(TemplateFileName = \"mytemplate.scriban\")]\n   private readonly IPrintable? aspect1 = null;\n}\n```\n\nAuto-generated accompanying source:\n\n```csharp\npartial class Person\n{\n   ..generated from file..\n}\n```\n\u003cbr\u003e\n\n## Partial template\n\nPartial template can be defined inline (from string) or from file.\n\nManually written source:\n\n```csharp\ninterface IPrintable\n{\n   int Length { get; }\n   int Count { get; }\n   void Print1();\n   void Print2();\n}\n\npublic partial class Person : IPrintable\n{\n   private void LogDebug(string name) { }\n\n   [BeaKona.AutoInterface]\n   [BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.PropertyGetter,\n        Filter = \"Length\", Language = \"scriban\", Body = \"return 1;\")]\n   [BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method,\n        Filter = \"Print(\\\\d)?\", Body=\"LogDebug(nameof({{interface}}.{{name}})); {{expression}};\")]\n   private readonly IPrintable? aspect1 = new PrinterV1();\n}\n```\n\nAuto-generated accompanying source:\n\n```csharp\npartial class Person\n{\n   int IPrintable.Length\n   {\n      return 1;\n   }\n   \n   int IPrintable.Count =\u003e this.aspect1!.Count;\n\n   void IPrintable.Print1()\n   {\n       LogDebug(nameof(IPrintable.Print1));\n       this.aspect1!.Print1();\n   }\n\n   void IPrintable.Print2()\n   {\n       LogDebug(nameof(IPrintable.Print2));\n       this.aspect1!.Print2();\n   }\n}\n```\n\n\u003cbr\u003e\n\nOther examples can be found in [wiki](https://github.com/beakona/AutoInterface/wiki/Examples).\n\n\u003cbr\u003e\n---\n\n![.NET Core](https://github.com/beakona/AutoInterface/workflows/.NET%20Core/badge.svg)\n[![NuGet](https://img.shields.io/nuget/v/BeaKona.AutoInterfaceGenerator)](https://www.nuget.org/packages/BeaKona.AutoInterfaceGenerator)\n","funding_links":[],"categories":["Source Generators","Do not want to test 112 ( old ISourceGenerator )"],"sub_categories":["Patterns","1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeakona%2FAutoInterface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeakona%2FAutoInterface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeakona%2FAutoInterface/lists"}