Extension methods

After watching a Dot Net Rocks TV show about LINQ I’ve become a bit concerned about some of the supporting changes to the underlying compilers. The first of these changes is the ability to create a class on the fly without any strong-typing, at least as far as the compiler is concerned – intellisense still works. I can just about swallow that on the grounds that it should only be used to speed up development in very specific cases…actually I’m not sure I can. But then came Extension Methods. From what I can gather the idea is that you can write a new method that acts upon a specific class and then you can inject or "extend" the class with your new method. So for example I could write:
 void function AppendGoodBye(ref string message){message+=" goodbye"}
which would mean I’d call it like:
string message = "I say ";
AppendGoodBye(ref message);
With an Extended method (and I’m not 100% on the exact syntax) you write something like:
void function AppendGoodBye(this string message){message+=" goodbye"}
you’d then call it like:
string message = "I say ".AppendGoodBye();
i.e. you’ve extended the string class.
Now at face value that’s all very clever, but I’m worried it’s gonna’ break the OO wide open. If I want to maintain that code where do I go looking for it? Normally I’d be looking in the string class, but where do I look for it now? Seems like a step in the wrong direction to me, I need to read a bit more about this.
This entry was posted in cSharp. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s