8

there are attributes in .NET (e.g. ObsoleteAttribute) which are able to prevent compilation or at least throw compile time warnings depending on their configuration.

How to write an attribute that is able to interfere with compilation? Is there a way to do this from outside Microsoft?

zzandy
  • 2,263
  • 1
  • 23
  • 43

2 Answers2

7

Obsolete attribute is "compiler magic" - you can't do something like this on your own without modifying the compiler. However, as always, there are workarounds - e.g. take a look at this and this thread.

Community
  • 1
  • 1
Saulius Valatka
  • 7,017
  • 5
  • 26
  • 27
2

Any attributes that exhibit this inside the compiler are special cases. The [Obsolete] behaviour is described in the C# spec (17.4.3), for example.

You could write a custom FxCop rule?

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900