Is there an annotation in .NET which allows methods or classes to be deprecated so that their use and their callers are identified by the compiler (cf @Deprecated in Java)
+31
A:
The [Obsolete]
attribute.
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:
<Obsolete("Use NewMethod() instead")> _
Public Sub OldMethod()
End Sub
Thorarin
2009-08-06 18:41:06
+1 for the compiler error
Lucas B
2009-08-07 13:24:00