Search code examples
c#attributesobsolete

C# custom obsolete attribute


I was wondering if it's possible to create a custom obsolete class. I need it and I hate the fact Obsolete shows up this warning before my input: SOMETHING is Obsolete:. I just want to give a warning/error when I use the field/method with ONLY my input, so for example:

[CustomObsolete("Hello")]
public int i = 0;

Will give warning/debug Hello.

Is this possible? If I use #warning/#error, it will ALWAYS show up the error/warning.


Solution

  • No, ObsoleteAttribute is effectively hard-coded into the C# compiler - there's no way of creating your own attribute that the C# compiler will understand as indicating that a member is obsolete.

    Personally I'd just go with ObsoleteAttribute - is it really that bad that the error message starts with "X is obsolete"?