【问题标题】:Is there a standard for the message when deprecating a type or method with another弃用另一个类型或方法时是否有消息标准
【发布时间】:2012-06-13 03:39:16
【问题描述】:

我用:

[Obsolete("Please use [NEW API] instead.")]

弃用公共 API,但我不确定 [NEW API] 的标准是什么。 以下示例似乎很标准:

[Obsolete("Please use Method2() instead.")] //This seems to be ok if Method2 is in the same class
[Obsolete("Please use Class2.Method1() instead.")] //This seems to be ok if we are referencing a different class in the same namespace
[Obsolete("Please use Namespace.Class2.Method1() instead.")] //This seems to be ok if we are referencing a different class in a different namespace

但是当您用带有 args 的特定方法替换 API 时,它开始变得模糊:

[Obsolete("Please use Method2(string, string) instead.")]

这是引用特定方法类型的正确方法还是包含变量名?例如:

[Obsolete("Please use Method2(string arg1, string arg2) instead.")]

现在更难的是,如果类型已移动到另一个程序集,例如:

[Obsolete("Please use Namespace.ClassName.Method2(), AssemblyName instead.")]
[Obsolete("Please use AssemblyName!Namespace.ClassName.Method2() instead.")]

哪个是正确的方法,还是有其他方法?

【问题讨论】:

  • 如果情况足够复杂,另一种选择是建立一个页面来描述各种用例以及他们应该考虑更改的内容,然后将 URL(永久的东西!)放在消息中。 :)

标签: c# .net standards deprecated obsolete


【解决方案1】:

我认为你在正确的轨道上,这与我过去所做的一致。我经常觉得 ObsoleteAttribute 可能有更多的重载(也许多个属性甚至意味着稍微不同的东西?)。看看 .NET 框架中的一些示例,这些示例与您提到的完全一样:

[ObsoleteAttribute("This class has been deprecated. Please use System.Xml.Xsl.XslCompiledTransform instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public sealed class XslTransform

[Obsolete("Please use Hashtable(int, float, IEqualityComparer) instead.")] 
public Hashtable(int capacity, float loadFactor, IHashCodeProvider hcp, IComparer comparer) : this(capacity, loadFactor) { 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多