Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disallow or 'hide' methods to stop the development team using them?

Tags:

c#

I work in a team of 20+ developers that includes a recent influx of newer members. Our coding standards state that the .First() extension method for IEnumerable should never be used, and instead that we should always use FirstOrDefault() and check for a null return.

I appreciate that some members may want to get into a discussion about training, enforcing coding standards or unit tests to pick up such transgressions, but in principle is it possible to cause the attempted use to throw a compile-time error?

like image 940
youthinkthisisntme Avatar asked Sep 01 '11 20:09

youthinkthisisntme


1 Answers

The best thing that you can do in terms of compile time help is:

  1. Make your OWN extension method called "First" that does nothing but throw an exception.

  2. Mark that method as "OBSOLETE" so that you get a compile-time warning.

I think that's the best you can do.

(some comments mentioned concern about the namespace... you would simply use the same namespace as Microsoft does [System.Linq] so that the compiler sees both).

like image 65
Timothy Khouri Avatar answered Nov 14 '22 21:11

Timothy Khouri