Mark method Obsolete except for calls within the same class

Advertisements

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?

>Solution :

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()
    {
        //...
    }
}

Leave a ReplyCancel reply