Oboslete attribute in C#

gpeipman
1,644 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Oboslete attribute

Usually breaking changes in code are prepared through multiple releases to provide backward support for systems that are not so easy to change. To bring coming changes straight to IDE and compiler .NET Framework has Obsolete attribute that can be used to decorate code artifacts that will be or are replaced by something else.

Here is the example of obsolete method. Take a look at compiler output when running this demo.

Describing the change

The fact that method is obsolete is often not enough as developers want to know how to update their code. For this the obsolete attribute supports description that shortly communicates next steps to developers or points out where more guidance about coming change can be found.

Here is the example of obsolete attribute with decsription. Run the demo and check compiler output now.

References

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content