How to throw compilation error from attribute?

there are attributes in .NET (for example ) that can prevent compilation or at least throw warnings about compilation time depending on their configuration. ObsoleteAttribute

How to write an attribute that can interfere with compilation? Is there any way to do this from outside Microsoft?

+6
source share
3 answers

Obsoletethe attribute is "compiler magic" - you cannot do something like this yourself without changing the compiler. However, as always, there are workarounds - for example, look at this and this stream.

+6
source

PostSharp: #

+3

Any attributes that appear inside the compiler are special cases. The behavior is [Obsolete]described, for example, in the C # specification (17.4.3).

Can you write your own FxCop rule ?

+1
source

All Articles