简体   繁体   中英

If I mark a method as Obsolete[“…”, true], what should be the return value? An arbitrary value?

I have a method that is being made obsolete (in fact completely unsupported) because the underlying concept is being removed. So, the method can't have any implementation and I made it throw new NotSupportedException() . Does it make sense to also cause a compilation error with the error parameter for Obsolete attribute? Or if I'm going to do that, should I just return an arbitrary value (since the method will never be run)? Can someone explain or link me to documentaiton of best practice?

you shouldn't change implementation of [Obsolete] method to always throw exception.

you are defeating whole purpose of this attribute, you will mark method that is working, as obsolete that means you no longer garauntee that in your next releases of your API that method will exist.

while method is marked as obsolete, other developers have some time to work on their code and cope with new changes. instead of just having their code broken up.

if you are going to throw exception always, you better remove that entirely, or have same implementation but mark it as [Obsolete] and remove it completely when its appropriate.

from MSDN

The Obsolete attribute marks a program entity as one that is no longer recommended for use . Each use of an entity marked obsolete will subsequently generate a warning or an error

did it say it always throw exception and its doesn't work anymore? nope. if your method doesn't work anymore, you made a breaking change so you have to either make it somehow work and mark it as obsolete, or remove it completely.

Another good point,

The Obsolete attribute can be used without arguments, but including an explanation of why the item is obsolete and what to use instead is recommended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM