{"id":16687195,"url":"https://github.com/redth/maui.generators.prototype","last_synced_at":"2025-04-10T00:20:25.220Z","repository":{"id":137487320,"uuid":"316608144","full_name":"Redth/Maui.Generators.Prototype","owner":"Redth","description":"A playground with some conceptual generators that could be used in Maui / Single Project","archived":false,"fork":false,"pushed_at":"2020-11-29T01:49:02.000Z","size":125,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-01T22:41:46.677Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Redth.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-27T22:01:17.000Z","updated_at":"2022-06-30T02:25:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"93a015cc-cc64-4e8c-92b9-800ba2db5f1b","html_url":"https://github.com/Redth/Maui.Generators.Prototype","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FMaui.Generators.Prototype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FMaui.Generators.Prototype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FMaui.Generators.Prototype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FMaui.Generators.Prototype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Redth","download_url":"https://codeload.github.com/Redth/Maui.Generators.Prototype/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131851,"owners_count":21052938,"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-10-12T15:08:09.553Z","updated_at":"2025-04-10T00:20:25.210Z","avatar_url":"https://github.com/Redth.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Maui.Generators.Prototype\nA playground with some conceptual generators that could be used in Maui / Single Project\n\n\n# Experiments\n\n\n## Shared Fonts\n\nThe generator can take items from your project such as:\n\n```xml\n\u003cItemGroup\u003e\n  \u003cSharedFont Include=\"OpenSans-Regular.ttf\" Alias=\"OpenSans\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\nYour font will automatically be included as an EmbeddedResource, and in addition, the source generator\nwill automatically generate code to register the font with Xamarin.Forms' registrar:\n\n```csharp\nusing System.CodeDom.Compiler;\nusing System.Reflection;\nusing Xamarin.Forms;\nusing Xamarin.Forms.Internals;\n\nnamespace Maui.Generated\n{\n  [GeneratedCode(\"Maui.Generators\", \"1.0.0.0\")]\n  internal class MauiGeneratedRegistrar\n  {\n    [ModuleInitializer]\n    internal static void Register()\n    {\n      FontRegistrar.Register(new ExportFontAttribute(\"OpenSans-Regular.ttf\")\n      {\n        Alias = \"OpenSans\"\n      }, Assembly.GetExecutingAssembly());\n    }\n  }\n}\n```\n\n\nUsing the `[ModuleInitializer]` attribute on the generated `Register()`  method will cause it to be invoked automatically at runtime.  This should almost always work, however it should be noted that the module initializer marked methods are only guaranteed to run before any other code is invoked from its assembly.\n\nIf an assembly is doing some sort of handler registration, it most likely is doing the registration for implementations or resources it contains, therefore the module initializer will always be called before the implementations are used anyway.\n\nIf an assembly contains things that don't need to be referenced by code (ie: just some fonts and no actual code), it would need to use some sort of `Init()` call to avoid being linked out.  I haven't thought of any great scenario which causes module initializers to be a problem yet.\n\nWe need to consider more scenarios where the module initializer could be problematic for each use case of generated code.\n\nFinally, if we have `\u003cSharedFont ` type items as the entry point, we can add some globbing pattern rules to the single project targets by default so fonts could be included simply by convention, for example:\n\n```\n\u003cItemGroup\u003e\n  \u003cSharedFont Include=\"Resources/Fonts/*.ttf;Resources/Fonts/*.otf\" /\u003e\n\u003cItemGroup\u003e\n```\n\nWhich would allow any `.ttf` or `.otf` font inside the project's `Resources/Fonts/` directory to be automatically included in the build, and have registration code generated and executed at runtime.\n\n\n### More experiments to come!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredth%2Fmaui.generators.prototype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredth%2Fmaui.generators.prototype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredth%2Fmaui.generators.prototype/lists"}