Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark method as obsolete for a single project

Due to the way our codebase works, I was advised to not edit certain methods in a shared codebase. Instead, I decided to make a new method that calls the old one and also does the new work our team wanted that method to do. The issue I am foreseeing is not everyone on the team being aware of the new method and still using the old one from the shared codebase.

TLDR:

Shared codebase has SharedCode.Function.

I created OurCode.Function which does some stuff, and then calls SharedCode.Function.

I cannot edit SharedCode.Function or it's containing project.

Is it possible to mark SharedCode.Function as obsolete within our project as a compiler warning somehow or otherwise mark that OurCode.Function essentially replaces it?

EDIT:

Might be pertinent to mention- these are logging functions, so if a dev accidentally calls SharedCode.Function instead of OurCode.Function, the only result is that we capture less data than we desired, it will still compile and run fine. This is a major reason I want to try to make it a compiler warning, so that any dev that doesn't know to use the new function will find out to.

like image 318
Garrett Cox Avatar asked Oct 17 '22 06:10

Garrett Cox


1 Answers

The shortest way is by adding the ObsoleteAttribute as an attribute to the method. Make sure to include an appropriate explanation:

[Obsolete("Method1 is deprecated, please use Method2 instead.")]
public void Method1()
{ … }
like image 92
Joey Phillips Avatar answered Nov 15 '22 05:11

Joey Phillips