Is there an ability in VB.NET to deprecate code?
I know that in C# there are 'attributes', and tags in java; is there anything similar in VB.NET, other than leaving a 'todo:
...?
In you examples the "Method1 is deprecated" part is rather redundant. By marking it as obsolete you are saying that it is indeed obsolete, so no need to restate it in the message. Especially since the resulting warning/error will read 'Method1' is obsolete: 'Method1 is deprecated, please use Method2 instead. '
You need to use the [Obsolete] attribute. Example: [Obsolete("Not used any more", true)] public class MyDeprecatedClass { //... }
Visual Basic (VB.NET) will continue to be supported by Microsoft. (It's not dead.) The language will no longer have new features added to it.
This attribute is found in the System namespace. The Obsolete attribute decorates a program element by putting the word “Obsolete” above it inside square brackets. Since it is an attribute, we can use either Obsolete or ObsoleteAttribute. [Obsolete] − is a no parameter constructor and is a default using this attribute.
There are attributes in VB.NET too:
Looks like this (before your function)
<Obsolete("This method is deprecated, use XXXX instead.")> _
And since VB.NET 10 (.NET 4 and later) we no longer need the underscore.
<Obsolete("This method is deprecated, use XXXX instead.")>
Use the [Obsolete] Attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With