Extension methods oddities
I’m back…I hope…After some complicated times which culminated in the floods which destroyed several regions of Madeira, I guess things are starting to coming back to normal…at least, that’s what I hope…I’ll probably return to blogging, though the rhythm won’t be the same as before.
One of the things I’ve been doing since I’ve migrated my code to C# 3.0 is defining and using extension methods. Another things which I tend *not* to do is use the this for qualifying access to a class’ members. Now, the thing is that *this* is required (ie, not optional) when you want to use an extension method in a class’ body. Suppose you’ve got class A and an extension method called T. Take a look at the following snippet:
class A {
public void DoSomething() {
this.T();
}
}
Since T is an extension method, you do really need to use the *this* qualifier. If you don’t, you’ll end up with a compiler error. I guess this is one of the oddities associated with extension methods (after all, they’re really static methods and we’re talking about a hack which does really help in several scenarios)…