{"id":23514452,"url":"https://github.com/svee4/RequiredStaticMembers","last_synced_at":"2025-08-28T08:31:20.951Z","repository":{"id":220745720,"uuid":"752479012","full_name":"svee4/RequiredStaticMembers","owner":"svee4","description":"Roslyn analyzer to enforce types to implement static virtual interface members","archived":false,"fork":false,"pushed_at":"2024-03-15T17:22:48.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-15T18:40:59.108Z","etag":null,"topics":[],"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/svee4.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}},"created_at":"2024-02-04T00:35:11.000Z","updated_at":"2024-03-03T19:06:30.000Z","dependencies_parsed_at":"2024-02-10T16:26:34.993Z","dependency_job_id":"aa70ca16-c65f-4526-93e5-4396483e2684","html_url":"https://github.com/svee4/RequiredStaticMembers","commit_stats":null,"previous_names":["svee4/requiredstaticmembers"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svee4%2FRequiredStaticMembers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svee4%2FRequiredStaticMembers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svee4%2FRequiredStaticMembers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svee4%2FRequiredStaticMembers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svee4","download_url":"https://codeload.github.com/svee4/RequiredStaticMembers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231242753,"owners_count":18346600,"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-12-25T14:01:44.744Z","updated_at":"2024-12-25T14:02:05.837Z","avatar_url":"https://github.com/svee4.png","language":"C#","funding_links":[],"categories":["Contributors Welcome for those"],"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"],"readme":"# RequiredStaticMembers\n\n[![NuGet](https://img.shields.io/nuget/v/Svee4.RequiredStaticMembers.svg?style=plastic)](https://www.nuget.org/packages/Svee4.RequiredStaticMembers/)\n[![GitHub license](https://img.shields.io/github/license/svee4/RequiredStaticMembers.svg)](https://github.com/svee4/RequiredStaticMembers/blob/main/license.txt)\n\n## Enforce types to implement static virtual interface members\n\n```cs\nusing Svee4.RequiredStaticMembers;\n\ninterface INode\n{\n    [Required]\n    public static virtual string Color =\u003e RequiredStaticMemberAccessException.Throw(nameof(Color));\n}\n\nclass GreenNode : INode\n{\n    // No error - property is implemented as expected\n    public static string Color =\u003e \"Green\";\n}\n\nclass BlueNode : INode\n{\n    // Error RSM001: Type 'BlueNode' does not implement required static member 'GetColor' from interface 'INode'\n}\n```\n\n## Why?\n\n- Problem: An interface with a `static abstract` member cannot be used as a generic, such as `List\u003cT\u003e`.\n- Solution: Replace the `abstract` modifier with `virtual`.\n- Problem: Deriving classes are no longer required to implement the member. The interface must provide an implementation, likely one that throws an exception at\n  runtime.\n- Solution: Use `[RequiredAttribute]` to enforce all deriving classes to implement the static member, making accidental calls to the default implementation\n  impossible.\n\n## How do i use it?\n\n1. Install the package from [Nuget](https://www.nuget.org/packages/Svee4.RequiredStaticMembers/)\n2. Give a static interface member the attribute `Svee4.RequiredStaticMembers.RequiredAttribute`\n3. All done! A deriving type that does not implement the given member will cause an error\n\n## I have an issue or I want to participate in development\n\nPlease open an issue or discussion\n\n## Acknowledgments\n\n- The repo of [Immediate.Handlers](https://github.com/viceroypenguin/Immediate.Handlers) was helpful in setting up csproj and CI/CD\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvee4%2FRequiredStaticMembers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvee4%2FRequiredStaticMembers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvee4%2FRequiredStaticMembers/lists"}