How many times have we designed a utility class for shared functions that can be used across different projects.  Some of these utility methods are written to extend existing types, adding methods like IsEmpty method for a dataset.

Eg;

 

public static bool IsDatasetEmpty(DataSet ds)

        {

            return (ds==null || ds.Tables.Count<=0 || ds.Tables[0]==null || ds.Tables[0].Rows.Count<=0); 

        }

.Net30 has a concept of extension methods, which makes it possible to extend types with additional methods.

Extension methods are declared by specifying the this keyword as a modifier on the first parameter of the methods. Extension methods can only be declared in static classes. The same method to extend Dataset can be implemented like this.

public static bool IsEmpty(this DataSet ds)

        {

            return (ds == null || ds.Tables.Count <= 0 || ds.Tables[0] == null || ds.Tables[0].Rows.Count <= 0);

        }

Extension methods are imported through the “using namespace directive”. Extension methods have all the capabilities of regular static methods and once imported extension methods can be invoked using instance method syntax.

 

For more information on what is in the store for .Net30 visit - http://msdn.microsoft.com/netframework/future/