|
|
Title | Use the Obsolete attribute in VB .NET |
Description | This example shows how to use the Obsolete attribute in VB .NET. |
Keywords | Obsolete, attribute, VB.NET, property |
Categories | VB.NET |
|
|
(One of my favorites.) The Obsolete attribute tells the Visual Basic IDE that a method is obsolete. You can indicate a string to display to the developer (usually telling what newer method to use instead) and you can determine whether the IDE treats using this method as a warning or an error.
In this example, the ObsoleteAllowed method is marked as obsolete but is allowed. The IDE flags the line calling the method and displays a warning in the Tasks pane.
The ObsoleteDisAllowed method is marked as obsolete and the final parameter to the attribute indicates that its use is not allowed. The IDE flags the line calling the method, displays an error message in the Tasks pane, and will not allow the program to run if this method is in use.
|
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
ObsoleteAllowed()
ObsoleteDisAllowed()
End Sub
<Obsolete("Don't use this routine any more. Use the new one " & _
"instead.")> _
Private Sub ObsoleteAllowed()
End Sub
<Obsolete("You MUST not use this routine any more. Use the " & _
"new one instead.", True)> _
Private Sub ObsoleteDisAllowed()
End Sub
|
|
|
|
|
|