{"id":15436408,"url":"https://github.com/gregsdennis/compilerattributes","last_synced_at":"2025-07-08T00:06:49.947Z","repository":{"id":60773973,"uuid":"144059843","full_name":"gregsdennis/CompilerAttributes","owner":"gregsdennis","description":"Custom compiler-sensitive attributes all over the place!","archived":false,"fork":false,"pushed_at":"2018-12-05T00:19:21.000Z","size":63,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T08:06:58.788Z","etag":null,"topics":["attributes","compiler"],"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/gregsdennis.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":"2018-08-08T19:39:59.000Z","updated_at":"2024-09-06T10:59:49.000Z","dependencies_parsed_at":"2022-10-04T15:31:12.343Z","dependency_job_id":null,"html_url":"https://github.com/gregsdennis/CompilerAttributes","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/gregsdennis%2FCompilerAttributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregsdennis%2FCompilerAttributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregsdennis%2FCompilerAttributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregsdennis%2FCompilerAttributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregsdennis","download_url":"https://codeload.github.com/gregsdennis/CompilerAttributes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249762393,"owners_count":21321928,"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":["attributes","compiler"],"created_at":"2024-10-01T18:50:27.597Z","updated_at":"2025-04-19T18:24:58.767Z","avatar_url":"https://github.com/gregsdennis.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CompilerAttributes\n\n[![NuGet version (CompilerAttributes)](https://img.shields.io/nuget/v/CompilerAttributes.svg?style=flat-square)](https://www.nuget.org/packages/CompilerAttributes/)\n[![Build status](https://ci.appveyor.com/api/projects/status/xcfe8editvax7l3m/branch/master?svg=true)](https://ci.appveyor.com/project/gregsdennis/compilerattributes/branch/master)\n[![MyGet Build Status](https://www.myget.org/BuildSource/Badge/littlecrabsolutions?identifier=d13bf0e6-34b1-4011-9242-5b134eb9f7c3)](https://www.myget.org/)\n[![Percentage of issues still open](http://isitmaintained.com/badge/open/gregsdennis/CompilerAttributes.svg)](http://isitmaintained.com/project/gregsdennis/CompilerAttributes \"Percentage of issues still open\")\n[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/gregsdennis/CompilerAttributes.svg)](http://isitmaintained.com/project/gregsdennis/CompilerAttributes \"Average time to resolve an issue\")\n\n[![Discuss on Slack](/Resources/Slack_RGB.png)](https://join.slack.com/t/manateeopensource/shared_invite/enQtMzU4MjgzMjgyNzU3LWQ0ODM5ZTVhMTVhODY1Mjk5MTIxMjgxZjI2NWRiZWZkYmExMDM0MDRjNGE4OWRkMjYxMTc1M2ViMTZiYzM0OTI)\n\n\u003ca href=\"http://www.jetbrains.com/resharper\"\u003e\u003cimg src=\"http://i61.tinypic.com/15qvwj7.jpg\" alt=\"ReSharper\" title=\"ReSharper\"\u003e\u003c/a\u003e\n\nWe've all been in the situation where we wanted the compiler to interpret custom attributes like it does for `Obsolete`.  Sadly, the compiler is hardwired to recognize only that one.\n\nUntil now!  This project is a 2-in-1 library that contains a Roslyn analyzer and a couple of attributes that you can use to create compiler-recognized attributes to your heart's content!\n\nIt's published via a Nuget package that gets installed both as an analyzer and as a library reference.  Here's how it works:\n\n## Install the Nuget packages\n\n```powershell\nInstall-Package CompilerAttributes\n```\n\n## Create an attribute\n\nThis attribute is what you'll use to decorate identifiers that should generate a warning or error.\n\n```csharp\npublic class MyAttributeAttribute : Attribute\n{\n}\n```\n\n***NOTE** By convention, attribute class names are suffixed with \"Attribute\".  When they're used, the suffix can be omitted.  Thus using the above attribute will look like `[MyAttribute]`.*\n\n## Decorate your attribute\n\nCompilerAttributes provides two attributes to mark your attribute as one that generates compiler output: `GeneratesWarningAttribute` and `GeneratesErrorAttribute`.  Pick one and decorate your attribute with it.\n\n```csharp\n[GeneratesWarning(\"{0} generated a warning\")]\npublic class MyAttributeAttribute : Attribute\n{\n}\n```\n\nThe single argument that is passed into the attribute is the message that will appear in the compiler output.  It supports up to a single string format argument (i.e. `{0}`) that will be replaced with the identifier name.\n\n## Enjoy the fruits of your labor\n\nNow whenever you use the `MyAttribute` attribute on something that thing will generate a compiler warning.\n\n```csharp\n[MyAttribute]\npublic class Class1\n{\n}\n\n// later\n\nvar instance = new Class1();        // this line generates a warning that says \"Class1 generated a warning\"\n```\n\n## Backstory\n\nI originally created this because I needed a way to indicate that some features I was working on for [Manatee.Json](https://github.com/gregsdennis/Manatee.Json) were going to be experimental, kind of an [opposite of the `Obsolete` attribute](https://stackoverflow.com/q/17487930/878701).\n\n## Contributing\n\nIf you have questions, experience problems, or feature ideas, please create an issue.\n\nIf you'd like to help out with the code, please feel free to fork and create a pull request.\n\n### The Project\n\nThis code uses C# 7 features, so a compiler/IDE that supports these features is required.\n\nThere are three solutions:\n\n- *ComplierAttributes* - This is the main solution that builds the Nuget package.  It contains three projects the main project, a test project, and a VISX generating project.  Though I don't publish from the VISX project, it's immensely useful for debugging.  It will start a new instance of VS under a different profile and install the VISX.  From there, you just need to open a solution.  That's where the other solution comes in.\n- *ClassLibrary1* - This has some boilerplate code that gives as many examples of usage of a symbol that I cared to think of.  Happily, all of these usages are underlined with little green squigglies, and the error output shows a bunch of warnings.\n- *AutoBuild* - This one just contains the main project.  I use it to isolate this project as part of my CI process.  Just ignore it.\n\n### Building\n\nDuring development, building within Visual Studio should be fine.\n\nI don't use the test project right now.  It was added as part of the template.  It could use some test cases... eventually.\n\n### Code style and maintenance\n\nI use [Jetbrains Resharper](https://www.jetbrains.com/resharper/) in Visual Studio to maintain the code style (and for many of the other things that it does).  The solution is set up with team style settings, so if you're using Resharper the settings should automatically load.  Please follow the suggestions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregsdennis%2Fcompilerattributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregsdennis%2Fcompilerattributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregsdennis%2Fcompilerattributes/lists"}