How can you mark code as “not for future use”

后端 未结 4 2505
你的背包
你的背包 2021-02-19 17:04

I often end up in a situation where I want to discourage other developers from continuing to use a method or class. For example, let\'s say I have two library methods \"A\" and

4条回答
  •  粉色の甜心
    2021-02-19 17:37

    Use ObsoleteAttribute.

    [ObsoleteAttribute("This method is obsolete. Call NewMethod instead.", false)] 
    public string SomeObsoleteMethod()
    {
       // ...
    }
    

    The last argument (IsError) will emit a compilation error if set to true, otherwise a warning will be given. You can disable the warnings by using #pragma 612, 618

    EDIT:

    Ok, fine, I relent. The solution you want appears to be:

    /// 
    /// Please don't use
    /// 
    public string SomeObsoleteMethod()
    {
       // ...
    }
    

    No compiler support at all.

提交回复
热议问题