Wednesday, March 11, 2009

Extension Methods in C#

Extension methods have been around long enough now that most people probably already know what they are and what they're for, so I'll keep this part pretty short. Extension methods allow a developer to add methods to an already existing CLR type without decorating or sub-classing the type. This provides flexibility to strongly-typed languages like C#. For example, the fluent interface of LINQ heavily leverages extension methods.

I've been dying to come up with a good reason to write some extension methods, but until recently, I hadn't had much need for it. Now, I've written an extension method or two, have started using them in production code, and I'm addicted! Hence, the blog post you're reading now.

I also think I'm going to try a new format for posting "living documents." Previously, I've posted documents with the intent to change them periodically and post update notices. The problem is, the update notice is useless as a unit of blogging in and of itself. As a result, I think I'm going to post new extension methods separately and tag them "extension methods." That way, each additional post has value in and of itself and it'll be easy to keep track of them by browsing to extension methods search label.

Also, a convenient RSS feed is available.

1 comment:

  1. First of all. Thanks very much for your useful post.

    I just came across your blog and wanted to drop you a note telling you how impressed I was with the

    information you have posted here.

    Please let me introduce you some info related to this post and I hope that it is useful for community.

    There is a good C# resource site, Have alook

    Thanks again