{"id":23079721,"url":"https://github.com/r-koubou/sgframework","last_synced_at":"2025-09-10T14:19:05.121Z","repository":{"id":44901040,"uuid":"330274504","full_name":"r-koubou/SGFramework","owner":"r-koubou","description":"Lightweight framework for C# 9.0 Source Generator","archived":false,"fork":false,"pushed_at":"2022-01-19T18:36:16.000Z","size":88,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-16T12:48:16.476Z","etag":null,"topics":["csharp","dotnet","nuget","roslyn","source-generation"],"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/r-koubou.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}},"created_at":"2021-01-16T23:01:48.000Z","updated_at":"2022-11-08T17:42:15.000Z","dependencies_parsed_at":"2022-09-16T03:41:23.911Z","dependency_job_id":null,"html_url":"https://github.com/r-koubou/SGFramework","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-koubou%2FSGFramework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-koubou%2FSGFramework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-koubou%2FSGFramework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-koubou%2FSGFramework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-koubou","download_url":"https://codeload.github.com/r-koubou/SGFramework/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229964395,"owners_count":18152031,"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","dotnet","nuget","roslyn","source-generation"],"created_at":"2024-12-16T12:48:47.595Z","updated_at":"2024-12-16T12:48:52.283Z","avatar_url":"https://github.com/r-koubou.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"SGFramework\n=================\n\n\n\nLightweight C#9.0 SourceGenerator Framework.\n\n\n\n## Feature\n\n- Wrapper of Microsoft.CodeAnalysis.ISourceGenerator\n    - A library for parsing attributes of type declarations in a few steps\n    - Provides a constant processing flow, allowing you to focus on implementing the necessary processing\n\n## Installation\n\nInstall from nuget (serach by \"SGFramework\" )\n\n## What code do I need to implement?\n\n### Attribute Parser\n\nImplement a parser per attribute with IAttributeArgumentParser.\n\n```C#\nusing SGFramework;\nusing SGFramework.TypeDeclaration;\n\nnamespace Sample\n{\n    internal class MyAttributeArgumentParser : IAttributeArgumentParser\n    {\n        public void ParseAttributeArgument(\n            int argumentIndex,\n            AttributeArgumentSyntax argumentSyntax,\n            SemanticModel semanticModel,\n            ExpressionSyntax argumentExpression,\n            IDictionary\u003cAttributeParamName, object\u003e result )\n        {\n            //\n            // argumentIndex is index of attribute parameter [My(arg1,arg2)]\n            //\n            switch( argumentIndex )\n            {\n                // e.g. [My(100, 200)]\n                case 0:\n                    result[ arg1 ] = argumentExpression.ToString(); // 100\n                    break;\n                case 1:\n                    result[ arg2 ] = argumentExpression.ToString(); // 200\n                    break;\n            }\n        }\n    }\n}\n```\n\n\n\n### Generator\n\nImplement a SourceGenerator subclass\n\n```c#\nusing Microsoft.CodeAnalysis;\n\nusing SGFramework;\nusing SGFramework.TypeDeclaration;\n\nnamespace Sample\n{\n    [Generator] // Must set a  Microsoft.CodeAnalysis.Generator attribute\n    internal class SampleGenerator : SourceGenerator\u003cTypeDeclarationSyntaxReceiver\u003e\n    {\n#if DEBUG\n        // if true, launch JIT Debugger\n        protected override bool LaunchDebuggerOnInit =\u003e false;\n#endif\n\n        protected override TypeDeclarationSyntaxReceiver CreateReceiver()\n            =\u003e new( this );\n\n        protected override void SetupAttributeArgumentParser( Dictionary\u003cAttributeTypeName, IAttributeArgumentParser\u003e map )\n        {\n            // Mapping inplementation of IAttributeArgumentParser with attribute name\n            map[ new AttributeTypeName( \"MyAttribute\" ) ] = new MyAttributeArgumentParser();\n        }\n\n        protected override void GenerateAttributeCode( GeneratorExecutionContext context )\n        {\n            // Mapping Attribute code on memory with GeneratorExecutionContext\n            context.AddSource( hintName1, code );\n            context.AddSource( hintName2, code );\n            :\n            :\n        }\n\n        protected override string GenerateCode(\n            TypeDeclarationSyntax declaration,\n            string nameSpace,\n            string typeName,\n            IDictionary\u003cAttributeTypeName, IDictionary\u003cAttributeParamName, object\u003e\u003e attributeTypeList )\n        {\n            // Generating your code with T4 etc\n            return code;\n        }\n    }\n}\n```\n\n\n\n## Reference your generator project from other C# Project\n\nif reference by `PrijectReference`, write following\n\n```xml\n    \u003cItemGroup\u003e\n        \u003cProjectReference Include=\"..\\Generator\\Generator.csproj\" OutputItemType=\"Analyzer\" /\u003e\n    \u003c/ItemGroup\u003e\n```\n\nnote:  attribute `ReferenceOutputAssembly` value  needs **true** (if set to false,analzer may not work)\n\n\n\n## Reference your generator (Nuget package) from other C# Project\n\n```xml\n    \u003cItemGroup\u003e\n        \u003cPackageReference Include=\"Generator\" Version=\"0.0.1\" /\u003e\n    \u003c/ItemGroup\u003e\n```\n\nSame as nuget package reference.\n\n\n\n## Implemented by SGFramrwork\n\n- ValueObjectGenerator\n    - https://github.com/r-koubou/ValueObjectGenerator","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-koubou%2Fsgframework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-koubou%2Fsgframework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-koubou%2Fsgframework/lists"}