Possible duplicate:
What are the benefits of extension methods you find?
All rights, first of all, I understand that this sounds debatable, but I do not want to be confrontational. I ask a serious question out of real curiosity (or maybe puzzling is the best word).
Why were .NET methods implemented in .NET? What benefits do they provide besides the fact that everything looks good (and “good” I mean “deceptively, like instance methods”)?
For me, any code that uses the extension method as follows:
Thing initial = GetThing(); Thing manipulated = initial.SomeExtensionMethod();
It is misleading, as it implies that SomeExtensionMethod is a member of Thing , which misleads the developers in faith (at least as a feeling of the gut ... you can deny it, but I definitely watched it) that (1) SomeExtensionMethod is likely to be implemented effectively, and (2) since SomeExtensionMethod really looks like part of the Thing class, it will certainly remain valid if Thing is revised at some point in the future (as long as the author of Thing knows that he / she does).
But the fact is that extension methods do not have access to protected members or to any internal operation of the class that they extend, therefore they are as prone to breakage as any other static methods.
We all know that the above can be easy:
Thing initial = GetThing(); Thing manipulated = SomeNonExtensionMethod(initial);
I think this is much more, due to the lack of a better word, honest .
What am I missing? Why are there extension methods?