{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/7875","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/7875/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/7875/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/7875/events","html_url":"https://github.com/dotnet/roslyn/issues/7875","id":125884456,"number":7875,"title":"Proposal: Preprocessor Directive Attributes","user":{"login":"alrz","id":3105979,"avatar_url":"https://avatars.githubusercontent.com/u/3105979?v=3","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-11T06:55:16Z","updated_at":"2016-01-11T13:32:52Z","closed_at":null,"body":"While using `#pragma warning` and `#pragma restore` is very common, there is no guarantee that you actually restore the disabled warning. And more often than not you just want to disable it for a single code construct, like a variable declaration or a block of code.\r\n```cs\r\n#pragma warning disable RS0013\r\nvar foo = new Foo( ... );\r\n#pragma warning restore RS0013\r\n```\r\nWith source-only attributes (#6671) this can be easily achieved with a dedicated attribute, like\r\n```cs\r\n[[disable(RS0013)]]\r\nvar foo = new Foo( ... );\r\n```\r\nThis attribute can be applied to ant piece of code that source-only attributes are allowed on, like classes, blocks, et cetera.\r\n\r\nAnother use case is in conditional compilation which can become very complicated over time,\r\n```cs\r\n[[if(DEBUG)]]\r\nclass C {}\r\n[[if(!DEBUG)]]\r\nclass C {}\r\n```\r\nNote that `ConditionalAttribute` only works with `void`-returning methods, while source-only attributes can be used on any language construct.\r\n\r\nAs a further consideration, I'd like to suggest Rust syntax for source-only attributes to make this clearer to the user,\r\n```cs\r\n#[if(DEBUG)]\r\nclass C : #[if(FOO)] IFoo { }\r\n```\r\nis equivalent to\r\n```cs\r\n#if DEBUG\r\nclass C \r\n#if FOO\r\n: IFoo \r\n#endif\r\n{ }\r\n#endif\r\n```\r\nAlthough, as you can see, applying these attributes on some places needs additional considerations."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/170549929","html_url":"https://github.com/dotnet/roslyn/issues/7875#issuecomment-170549929","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/7875","id":170549929,"user":{"login":"HaloFour","id":10102290,"avatar_url":"https://avatars.githubusercontent.com/u/10102290?v=3","gravatar_id":"","url":"https://api.github.com/users/HaloFour","html_url":"https://github.com/HaloFour","followers_url":"https://api.github.com/users/HaloFour/followers","following_url":"https://api.github.com/users/HaloFour/following{/other_user}","gists_url":"https://api.github.com/users/HaloFour/gists{/gist_id}","starred_url":"https://api.github.com/users/HaloFour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaloFour/subscriptions","organizations_url":"https://api.github.com/users/HaloFour/orgs","repos_url":"https://api.github.com/users/HaloFour/repos","events_url":"https://api.github.com/users/HaloFour/events{/privacy}","received_events_url":"https://api.github.com/users/HaloFour/received_events","type":"User","site_admin":false},"created_at":"2016-01-11T13:32:52Z","updated_at":"2016-01-11T13:32:52Z","body":"Java has the similar `@SuppressWarnings` annotation which is useful for disabling warnings within a specific scope without having to worry about re-enabling the warning later.  I think that could be quite useful.\r\n\r\nAs for conditionals, I could see that getting weirdly complicated and fast."}}