{"id":13629450,"url":"https://github.com/SleepWellPupper/AttributeFactoryGenerator","last_synced_at":"2025-04-17T09:33:53.914Z","repository":{"id":206458861,"uuid":"716790757","full_name":"PaulBraetz/AttributeFactoryGenerator","owner":"PaulBraetz","description":"Generate factories for creating attribute instances from `AttributeData` instances.","archived":false,"fork":false,"pushed_at":"2023-11-22T15:23:50.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-12T13:32:18.796Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PaulBraetz.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}},"created_at":"2023-11-09T22:04:19.000Z","updated_at":"2024-01-05T21:12:48.000Z","dependencies_parsed_at":"2023-11-10T07:17:15.630Z","dependency_job_id":"56dd20ee-646e-46b1-b243-f6075b51633f","html_url":"https://github.com/PaulBraetz/AttributeFactoryGenerator","commit_stats":null,"previous_names":["paulbraetz/attributefactorygenerator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulBraetz%2FAttributeFactoryGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulBraetz%2FAttributeFactoryGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulBraetz%2FAttributeFactoryGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulBraetz%2FAttributeFactoryGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PaulBraetz","download_url":"https://codeload.github.com/PaulBraetz/AttributeFactoryGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751127,"owners_count":17196575,"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":[],"created_at":"2024-08-01T22:01:11.068Z","updated_at":"2025-04-17T09:33:48.637Z","avatar_url":"https://github.com/PaulBraetz.png","language":"C#","funding_links":[],"categories":["Contributors Welcome for those","Meta - libs and generators for other generators"],"sub_categories":["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","Other"],"readme":"# RhoMicro.AttributeFactoryGenerator\n\nAre you creating source generators for C#? Are you using attributes to allow your consumers to instruct your generator? Are you dissatisfied with the amount of boilerplate you have to write in order to extract those instructions from the roslyn api? \n\nThen this project could be of use to you!\n\n## Key Features \u0026 Limitations\n- Generate Factory for parsing attribute instance from `AttributeData`\n- Generate helper functions for retrieving instances of your attribute from an `IEnumerable\u003cAttributeData\u003e`\n- Parse type properties as `ITypeSymbol`s\n\n- The attribute type (or semantically equivalent type) has to be available to the generator\n\n## How to use\n\nInstall the generator through [nuget](https://www.nuget.org/packages/RhoMicro.AttributeFactoryGenerator)\n\nIn the assembly through which I distribute the attributes, I declare one:\n```cs\n[AttributeUsage(AttributeTargets.Class)]\npublic partial class TestGeneratorTargetAttribute : Attribute\n{\n    public TestGeneratorTargetAttribute(String name, Int32[] ages)\n    {\n        Name = name;\n        Ages = ages;\n    }\n    public TestGeneratorTargetAttribute(Type type) =\u003e Type = type;\n\n    public String Name { get; }\n    public Int32[] Ages { get; }\n    public Type? Type { get; set; }\n}\n```\n\nThen, in the generator assembly, I add a link to the source file above, as well as a second partial declaration like so:\n```cs\n[GenerateFactory]\npartial class TestGeneratorTargetAttribute\n{\n    [ExcludeFromFactory]\n    private TestGeneratorTargetAttribute(System.Object typeSymbolContainer) =\u003e\n        _typeSymbolContainer = typeSymbolContainer;\n}\n```\nThe constructor above is required in order to construct an instance when the consumer made use of a constructor taking at least one parameter of type `Type`.\n\nFor every constructor that takes at least one parameter of type `Type`, an equivalent factory constructor is required. These are expected to take an instance of `Object` instead of the type and assign it to the generated helper field.\n\nThis way, a generated helper property of type `ITypeSymbol` may be used to retrieve the type used by the consumer in their `typeof` expression.\n\n\nUse the generated factory and helper methods like so:\n```cs\nImmutableArray\u003cAttributeData\u003e attributes = \n    symbol.GetAttributes();\n\nIEnumerable\u003cTestGeneratorTargetAttribute\u003e allParsed =\n    attributes.OfTestGeneratorTargetAttribute();\n\nTestGeneratorTargetAttribute singleParsed =\n    TestGeneratorTargetAttribute.TryCreate(attributes[0], out var a) ? \n    a : \n    null;\n\nsingleParsed = \n    symbol.TryGetFirstTestGeneratorTargetAttribute(out var a) ? \n    a : \n    null;\n```\nThe generated extension method `OfTestGeneratorTargetAttribute` will return all instances of `TestGeneratorTargetAttribute` found in the symbols list of attributes.\n\nThe generated extension method `TryGetFirstTestGeneratorTargetAttribute` attempts to retrieve the first instance of `TestGeneratorTargetAttribute` found on the symbol.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSleepWellPupper%2FAttributeFactoryGenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSleepWellPupper%2FAttributeFactoryGenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSleepWellPupper%2FAttributeFactoryGenerator/lists"}