user746461
user746461

Reputation:

How to discourage a .NET library method?

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?

Upvotes: 3

Views: 139

Answers (1)

Dennis
Dennis

Reputation: 20571

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.

Upvotes: 4

Related Questions