Search code examples
c#extension-methodsfuture-proof

Extension Methods forward compatible


With extension methods we can easily add methods to any type. Obviously this opens the possibility in a future version of .net the extension method could no longer get called (for example the type now includes a method with identical signature to the extension method).

Should this be a concern?

If so, how should I deal with this and design my extension methods as to minimise code changes should this happen?


Solution

  • If the framework is changed so much in the future, there will always be compatibility issues. If a new framework method is added with the same name as your extension method, it is quite likely that they have the same, or at least very similar functionality and a refactoring is due anyways.

    I think that the power of the extension methods is too large to ignore just because of this risk.