We are using a 3rd party assembly which has a problematic method. Is there some way to alert our developers that the method should not be used, preferably at compile time but run-time is ok too. Something like an Obsolete attribute but for another assembly. I can't override the method because it's not virtual.
Asked
Active
Viewed 232 times
-1
-
@HimBromBeere He's asking for a way to mark a method obsolete in a third party assembly he has no access to. There is no way to do that, that I know of. – InBetween Mar 08 '17 at 09:58
-
1Then it might be answered here: http://stackoverflow.com/questions/8316869/add-an-attribute-to-another-assemblys-class – MakePeaceGreatAgain Mar 08 '17 at 10:04
1 Answers
0
The only way I can see that this is possible is to wrap the API in your own assembly and get the developers to use your assembly instead of the provided one.
using MyAPI;
public class MyWrapper
{
private MyAPI _api;
public MyWrapper()
{
_api = new MyAPI(); //Especially if you want to do some inits
}
public void APIMethod()
{
_api.APIMethod();
}
}
My using the same method names, it will allow your developers to just replace the instantiation of the object with the new class, or even more cheekily, call the class the same thing and change the namespace.
Then, you can either omit the offending method(s) or mark them as obsolete.
You could even use the T4 templates to generate the code for you so you can regenerate if the API changes. If you use reflection, you may not even have to write the T4...
For nmore info on T4 - https://msdn.microsoft.com/en-us/library/dd820614.aspx
Hope this was useful.

Rendition
- 494
- 2
- 12
-
If I wrapped, I'd be just trading in one problem for another. What would be the issues if I created a class that inherited (not wrapped) the method's class and then shadowed the method. Is that too problematic? – BSalita Mar 08 '17 at 19:52
-
-
@BSalita Not sure what you mean about trading one problem for another... You can achieve what you want by doing this and if you use reflection and code generation, you only have to ever do it once. You cannot override because you pointed out that the method you want to hide is not virtual, so you're out of luck I'm afraid. – Rendition Mar 09 '17 at 10:02