George Duckett
George Duckett

Reputation: 32418

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?

Upvotes: 5

Views: 186

Answers (3)

Anders Abel
Anders Abel

Reputation: 69250

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.

Upvotes: 6

roken
roken

Reputation: 3994

Use obscure method names that would never be used in the framework.

edit -- perhaps obscure wasn't the most appropriate word, please substitute with meaningful but less common verbage

Attempting to avoid signature conflicts is really the only strategy to avoiding the hassle of code rework (assuming the functionality of the extension method needs to be preserved and not simply converted to the framework's definition of the method).

Upvotes: 0

Claudio Redi
Claudio Redi

Reputation: 68400

I'm afraid that the only thing you can do is providing unique enough names to your extension methods so you're 100% sure you will never have a conflict.

Not talking about adding the name of your cat to the method's name, just try to be more creative :)

Upvotes: 0

Related Questions