How to throw compilation error from an attribute?

前端 未结 3 1835
北荒
北荒 2021-01-12 11:12

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.

相关标签:
3条回答
  • 2021-01-12 11:31

    Using PostSharp: Generating a custom compile time warning C#

    0 讨论(0)
  • 2021-01-12 11:33

    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.

    0 讨论(0)
  • 2021-01-12 11:49

    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?

    0 讨论(0)
提交回复
热议问题