Posted on June 25, 2008 10:15 by lbrown

Since I can remember, helper classes have been the backbone of coding since they comprise all the utilities that are missing in the .Net framework.  The downside is that one must keep track of all the assemblies, namespaces and various implementations as the toolset grows.  This can be a daunting task when considering each client’s library and the exhaustive resources available in the developer community. Wouldn’t be nice if we could simply extend the functionality of our existing libraries?

.Net 3.5 now allows classes to be extended by using a specific type of method declaration.

//The key work 'this' is included at the beginning 
//of the parameter list with the type to be 
//extended.  You can then do any type of implementation you like 
public static void DoSomething(this string str) 
{   
}

The following attached example illustrates taking a simple helper class used for encrypting strings and converting it into an extension that becomes part of the .Net framework. 

ExtensionExample.zip (94.54 kb)



Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


 

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

November 20. 2008 19:33

|