Home > Software design >  Mark method Obsolete except for calls within the same class
Mark method Obsolete except for calls within the same class

Time:09-20

I want to mark a method as Obsolete only for callers from out of its class, while letting methods in its class call it without a warning.

Is that possible?

CodePudding user response:

You could extract the method content to a new private method. Internally you would use the private one.

public class YourClass
{
    [Obsolete]
    public void YourMethod()
    {
        YourMethodLogicExtractedToPrivateMethod();
    }

    private void YourMethodLogicExtractedToPrivateMethod()
    {
        //...
    }
}
  • Related