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?
The best thing that you can do in terms of compile time help is:
Make your OWN extension method called "First" that does nothing but throw an exception.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With