The Obsolete Attribute

One of the consultants I work with told me about an alternative use of the Obsolete attribute last week.  Its original intent was to identify methods and classes that shouldn’t be used anymore.  But using this:

[Obsolete(“”,true)]

turns out to be a rather nice refactoring tool as well.  Passing “true” as the second parameter instructs the compiler to flag all uses of a method or class so decorated as errors.  So far, this practice has helped me hunt down the one instance in code where a particular method was used.  Today, I should be able to eliminate an unnecessary custom exception class with it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.