Marking native methods as deprecated / deprecated?

In .NET, you can mark some methods as deprecated so that developers are warned when they try to use the deprecated method.

<Obsolete("Do not call this method.")> Private Sub FormerMethod() 

The fact is that you can only do this within the classes that you manage. What do you do when you want your developers to avoid using certain methods in classes provided in .NET or at the provider?

For example, what if you want your developer to prefer some custom extension method to a DataTable rather than Select . I would not want to define a custom version of the DataTable class if I were only to abandon Select . This would leave us with the need for the police to use a regular table.

I know that there are tools like (FxCop) that help enforce coding standards; however, my question is whether this can be handled without any third-party tool.

+4
source share
2 answers

Although you may not like the answer, I think packaging would be the right choice.

For a third-party vendor code, packaging should only be required to obtain a level of abstraction for unit testing. And, as a wrapper, you can apparently mark methods as Obsolete .

For .NET objects, this is a little trickier. Obviously, someone can just turn on the namespace and go to the city; I do not believe that for this problem, as you want, there is a โ€œonly codeโ€ solution, different from doing an integration test that searches for your solution and fails when that particular method is called that you donโ€™t like.

+2
source

If you want to mark the .Net Framework class as deprecated, you can override it in one of the common \ infrastructure classes that everyone uses.

Example:

 namespace System.ComponentModel { [Obsolete("Please do not use BackgroundWorker. Use class XXXX instead.")] public class BackgroundWorker { } } 

This can be done for certain methods, expanding the original .Net Framework class, and then overriding certain methods that call the base method, but are decorated with the Obsolete attribute.

However, you will need to enable the definition of a circular class (possibly using the assembly assembly alias).

+2
source

All Articles