Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discourage a .NET library method?

Tags:

c#

For example we don't want our developers to use string.Contains; instead they should use string.IndexOf.

Is it possible to mark string.Contains obsolete?

Is it possible to hide the method from IntelliSense?

Is there any (visual studio) tool catching and preventing the use of a .net method?


1 Answers

There are a few approaches you can take.

  1. Talk to your team, discuss why string.IndexOf is preferred.
  2. Use pull requests to review code before merge to master (assuming you're using git).

If you want feedback whilst coding, you can implement Convention Tests or as suggested in the comments a Rosylyn Analyser.

I recently wrote a Rosylyn Analyser for my DateTimeProvider package - the analyser picks up usages of DateTime and suggests DateTimeProvider.

like image 165
Dennis Avatar answered Jan 21 '26 19:01

Dennis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!