Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obsolete library class

Tags:

c#

What is the best way to prevent C# programmer from using particular library class?

Class is from external assembly so it is impossible to use [Obsolete] attribute on it. I tried to use Resharper custom patterns but it seems not to support generics types.

like image 237
Arkadiusz Wojcik Avatar asked Oct 18 '12 09:10

Arkadiusz Wojcik


2 Answers

Patch the library method/class (there are several plugins for Reflector) - add DeprecatedAttribute, or modify its code to throw an exception, for example.

You can also make a special unit test which runs at CI server and fails if a particular deprecated item usage indicated.

like image 142
mikalai Avatar answered Oct 12 '22 23:10

mikalai


You can disassemble the library with ildasm, add [Obsolete(true)] attributes and reassemble with ilasm.

You might be able to find some assembly edit tool, like Reflexil together with a trial of Reflector.

Note that if you edit an assembly you loose all signing and stuff.

like image 32
Albin Sunnanbo Avatar answered Oct 13 '22 00:10

Albin Sunnanbo