[英]what is the .NET equivalent of @Deprecated in java?
.NET中是否有注释允许方法或类被弃用,以便编译器识别它们的使用和调用者(参见Java中的@Deprecated)
The [Obsolete]
attribute. [Obsolete]
属性。
You can add a comment on what people should be using, for example: 您可以添加对人们应该使用的内容的评论,例如:
[Obsolete("Use NewMethod() instead")]
public void OldMethod()
{
}
If you want to generate a compiler error when people use your method: 如果要在人们使用您的方法时生成编译器错误:
[Obsolete("Use NewMethod() instead", true)]
public void OldMethod()
{
}
This is an example for a method, but it can be used on almost any attribute target. 这是一个方法的示例,但它几乎可以在任何属性目标上使用。 See here for full docs.
请参阅此处获取完整文档。
Since the question was edited slightly, I'll add the VB.NET syntax as well, to cover the most common .NET languages: 由于问题略有编辑,我还将添加VB.NET语法,以涵盖最常见的.NET语言:
<Obsolete("Use NewMethod() instead")> _
Public Sub OldMethod()
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.