c# - Usage of extension methods for framework types -


in new line of work have been told avoid using extension methods types (or organization) have no control over, meaning external libraries, framework types such string, list, , others.

the argument given bad if framework developer decides implement method has same names and/or parameters extension method.

while problem may arise, argument reduces usability of extension methods zero. argument considered valid? not suggesting use extension methods everywhere, know of similar arguments , against it.

it's argument has some merit, in lots of cases problems can avoided:

  • if control code , can update if necessary, can write unit tests detect problem , correct if occurs. (i assume you'd validating update external library before deploying anyway.)
  • if trust external library developer follow normal practices backward compatibility, shouldn't adding members interfaces anyway, break existing implementations... @ least write extension methods interfaces.
  • if extension methods have names very unlikely added external libraries, practically speaking it's not issue. example, if company writes frobulators, , that's term specific you, writing

    public static frobulator tofrobulator(this string frobulator) 

    really isn't going problem in reality.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -