Click here to Skip to main content
11,645,087 members (71,224 online)
Click here to Skip to main content

Tagged as

Use “Obsolete” attributes to indicate Obsolete Methods

, 3 Sep 2010 CPOL 13K 1
Rate this:
Please Sign up or sign in to vote.
In this post, I have explained how you can mark methods as obsolete using obsolete attributes which are not in use or may be removed in upcoming builds.

In this post, I have explained how you can use Obsolete attributes to mark some methods which are no longer in use or may be removed in future releases of the class. During the development cycle, we may need to change the name or declaration of certain methods which may be used by some other developers. In this case, if you changed the name or declaration of that method, the application may crash in different points of times as it’s being used by other developers in the application. In this case, you can use System.ObsoleteAttributes class to generate compiler warning and indicate the method as Obsolete.

1

Let’s discuss this with an example. Suppose we are having a Student class which has GetStudentInfo() method which returns the student's information.

2

Now this class is being used by many other developers to get the student information.

3

If you want to change the name or declaration of GetStudentInfo() methods, it may cause the application crash or application build error as this method is being used by many developers.

4

To overcome this problem, and maintain the compatibility you can use “Obsolete” attributes to the old methods and define a new method and show a proper message to other developers.

5

These changes won’t be cause for  any code break or application error. Other developers who are already using the GetStudentInfo() method will get an Compiler warning “Use GetStudentDetails instead of GetStudentInfo" .

6

And any new developer who is going to consume the GetStudentInfo() method will get a tool tip message that “Use GetStudentDetails Instead of GetStudentInfo".

7

Summary

In this post, I have explained how you can mark methods as obsolete using obsolete attributes which are not in use or may be removed in upcoming builds.

Hope this post will help you!

Filed under: ASP.NET, C#, General, Tips and Tricks, Visual Studio

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Abhijit Jana
Technical Lead
India India
.NET Consultant | Former Microsoft MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author | Speaker | Geek | Blogger | Husband

Blog : http://abhijitjana.net
Web Site : http://dailydotnettips.com
Twitter : @AbhijitJana
My Kinect Book : Kinect for Windows SDK Programming Guide

You may also be interested in...

Comments and Discussions

 
GeneralThanks Jana Pin
Programmer 127-Feb-14 19:35
memberProgrammer 127-Feb-14 19:35 
GeneralMy vote of 5 Pin
Abhinav S3-Sep-10 18:25
memberAbhinav S3-Sep-10 18:25 
GeneralRe: My vote of 5 Pin
Abhijit Jana3-Sep-10 20:02
mvpAbhijit Jana3-Sep-10 20:02 
GeneralMy vote of 5 Pin
KunalChowdhury3-Sep-10 6:04
mentorKunalChowdhury3-Sep-10 6:04 
GeneralRe: My vote of 5 Pin
Abhijit Jana3-Sep-10 17:46
mvpAbhijit Jana3-Sep-10 17:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150731.1 | Last Updated 3 Sep 2010
Article Copyright 2010 by Abhijit Jana
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid