{"id":13629000,"url":"https://github.com/LokiMidgard/AutoInvoke.Generator","last_synced_at":"2025-04-17T04:32:47.634Z","repository":{"id":187929861,"uuid":"677832379","full_name":"LokiMidgard/AutoInvoke.Generator","owner":"LokiMidgard","description":"A generator that generates a method that invokes, a specified generic method, for ever Type in your project that sattisfis a defined constraint","archived":false,"fork":false,"pushed_at":"2024-04-25T18:26:07.000Z","size":86,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T18:04:39.022Z","etag":null,"topics":["csharp-sourcegenerator","sourcegenerator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LokiMidgard.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2023-08-12T19:33:55.000Z","updated_at":"2024-08-20T23:43:09.000Z","dependencies_parsed_at":"2024-01-06T09:53:28.539Z","dependency_job_id":"395d5d29-7ad3-4269-b95e-e57d646d723e","html_url":"https://github.com/LokiMidgard/AutoInvoke.Generator","commit_stats":null,"previous_names":["lokimidgard/autoinvoke.generator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LokiMidgard%2FAutoInvoke.Generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LokiMidgard%2FAutoInvoke.Generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LokiMidgard%2FAutoInvoke.Generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LokiMidgard%2FAutoInvoke.Generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LokiMidgard","download_url":"https://codeload.github.com/LokiMidgard/AutoInvoke.Generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249316017,"owners_count":21249876,"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-sourcegenerator","sourcegenerator"],"created_at":"2024-08-01T22:01:01.375Z","updated_at":"2025-04-17T04:32:43.130Z","avatar_url":"https://github.com/LokiMidgard.png","language":"C#","readme":"[![NuGet](https://img.shields.io/nuget/v/AutoInvoke.Generator.svg?style=flat-square)](https://www.nuget.org/packages/AutoInvoke.Generator/)\n[![GitHub license](https://img.shields.io/github/license/LokiMidgard/AutoInvoke.Generator.svg?style=flat-square)](https://tldrlegal.com/license/mit-license#summary)\n# AutoInvoke\n\nThis Generator let you anotate an Parameterless Generic Method with exactly one TypeArgument.\n\nIt will then generate a method with the same name and no type arguments that calls your anotated\nmethod for every (non static) Type decleared in your project, that satisfies the type constraints.\n\n\n\n## Sample\n\nAssume you have the following Interface:\n\n```c#\ninternal interface IFileLoder {\n    public abstract static IFileLoder Init(string path);\n    public abstract static string FileExtension { get; }\n}\n```\n\nThis describes a File loader for different types in our project.\n\nAnd following implementation: \n\n```c#\ninternal class AudioLoader : IFileLoder {\n    public static string FileExtension =\u003e \".mp3\";\n\n    public static IFileLoder Init(string Path) {\n        return new AudioLoader(path);\n    }\n    // the rest of the code...\n}\n```\n\nWhich defines how we want to load mp3 files.\n\nWe now want to automaticly get a list of all `IFileLoader` so we know what files we can handle,\nand we do not want to manualy handel such a list. \n\nAn Implementation could look like this:\n\n```c#\ninternal delegate IFileLoder LoadFile(string path);\ninternal partial class FileHandler {\n    private readonly Dictionary\u003cstring, LoadFile\u003e loaders = new();\n\n    public FileHandler() {\n        LoadLoaders();\n    }\n\n    public void LoadFile(string file) {\n        if (loaders.TryGetValue(Path.GetExtension(file), out var loaderFactory)) {\n            var loader = loaderFactory(file);\n            // use loader to do things\n        }\n    }\n\n\n    [AutoInvoke.Generator.FindAndInvoke]\n    public void LoadLoaders\u003cT\u003e() where T : IFileLoder {\n        this.loaders.Add(T.FileExtension, T.Init);\n    }\n}\n```\n\nThe field loaders will have all extensions our code can handle, and has to every extension\nthe corresponding `Init`-Method.\n\nThe Generated code will look like this:\n\n```c#\npartial class FileHandler {\n    private void LoadLoaders() {\n        LoadLoaders\u003cAutoInvoke.Generator.Example.AudioLoader\u003e();\n    }\n}\n```\n\n\n## Featurs and limitations\n\n- You can control wich type of types shold get called. E.g. by\n  default no calls are generated for abstract classes or types defined in referenced Assemblys. But you can overide this setting\n- The anotated method can be static\n- If the anotated method has parameters the generated method has the same parametrs\n- If the return type is not `void` the generated methods returntype is an array of the return type of the attributed method\n\n### Limitations\n- When using multiple Type Parameters, one Type Parameter must contain all others (transitiv) like `Foo\u003cT1, T2, T3\u003e() where T1: IComparable\u003cT2\u003e where T2 : IComparable\u003cT3\u003e`\n- You can't call static Types. Generics do not allow this.\n\n\n","funding_links":[],"categories":["Content","Source Generators"],"sub_categories":["125. [AutoInvoke.Generator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/AutoInvoke.Generator) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category","Other"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLokiMidgard%2FAutoInvoke.Generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLokiMidgard%2FAutoInvoke.Generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLokiMidgard%2FAutoInvoke.Generator/lists"}