2

Disclaimer: I'm not asking how to Selectively suppress custom Obsolete warnings.


Background

I've got a property I wish to mark as obsolete.

This property is part of a solution that is wrapped in a NuGet and is used by many other solutions and branches, without proper semantic versioning.

Many of these other solutions and branches will not compile if there are any errors. So if I mark the property as obsolete, there will be a warning and numerous solutions and branches will consequentially fail.

I know the warnings can be suppressed with

#pragma warning disable 612, 618
    int a = foo.GetObsoleteProperty;
#pragma warning restore 612, 618

...but it is impractical to edit each of the uses of GetObsoleteProperty in each of these places.

Bottom line:

Is there a way to mark a property as Obsolete - but never generate a warning?
(Yes, I know this violates the general idea of marking a property as obsolete.)


Some alternatives I've considered which aren't exactly what I'm looking for:

  • Using an XML comment
  • Using EditorBrowsableAttribute, which doesn't work
Yehuda Shapira
  • 8,460
  • 5
  • 44
  • 66
  • 2
    Good question. *"Yes, I know this violates the general idea of marking a property as obsolete"* ... which is why I assume that there won't be a good answer to your question. I would argue that if a user of your library configured their compiler to treat Obsolete warning as errors, they *want* their build to fail when obsolete methods are used (otherwise, why would they configure their Visual Studio like that?). I would encourage you, as the library developer, to respect that choice and let their build fail, rather than saying "I know better". – Heinzi Jul 23 '20 at 11:47
  • @Heinzi, you've got some good points. I wrote the question half-expecting the answer to be "you can't." The "customers" are all within out own company, and some of their choices are due to policy rather than an actual need or requirement. – Yehuda Shapira Jul 23 '20 at 11:53
  • 2
    Well, that means that you now have a good reason for getting the broken policy fixed. :-) I say that half-jokingly, because I know that changing policies can be hard. I do think that this is an interesting question and I am looking forward to any answers that you might get. – Heinzi Jul 23 '20 at 11:55
  • @YehudaShapira,I suggest that when you use obsolete properties, you can also mark [obsolete] on the test method. This method can effectively eliminate the warning. – Jack J Jun Jul 24 '20 at 08:41

0 Answers0