2006-08-25

Extension Methods

Recently at work we had a requirement to have enum values displayed as proper words rather than camle cased. But you can't override the ToString method. But what about using the Extension Methods feature of c# 3.0. Now it seems like agood idead to do what upon future investigate you can't override methods like you would a virtual, you can only add new methods. So then i begs the point, what is the point of Extension Methods. The only case that i can see is if the class is sealed in a 3rd party library that you can't change, that you want to add a method, rather than having a Utils class to do the work for you. Now this is good, becuase then you can see all the methods in the visual studio intellisense. But if you own the class, then there really is no point, you would just add the method yourself.

The could be a way to use numerous different methods with the same name, but in different namespaces, but i haven't fully thought about that yet, and propably wont until 3.0 has gone into release.

Here are some links, though they are kind of old:
http://blah.winsmarts.com/2006/05/18/demystifying-c-30--part-3-extension-methods.aspx
http://mtaulty.com/communityserver/blogs/mike_taultys_blog/archive/2006/03/20/5798.aspx
http://www.cincomsmalltalk.com/userblogs/malby/blogView?showComments=true&entry=3304188302
http://blogs.msdn.com/abhinaba/archive/2005/10/21/483337.aspx