Some Commodore 64 Mixes from Mark VII
April 12th Carolina IT Professionals Group Meeting
Resume Review and Coffee Too
Ruby on Rails Position at Swivel
iPod Nano versus the iRiver
career jobs headhunter grails java rails charlotte nc
MCSD, SCJP, Linux+, CSM
Oxcite
Charlotte ALT.NET
Matthew Lefevre Wiki Articles
Lefevre Genealogy at matthewlefevre.com Charlotte Jobs Employment Career Recruiters Headhunter Robert Half Ettain Apex Job Recruiter








 RSS  | The Last 15 Posts  | The Complete Entry List

Making Your .NET Strings More Groovy

2008-06-06 06:56:00
This is probably the first of a number of posts I'll be writing about uses for C#'s Extension Method capabilities.
The code below will add a Groovy-like execute() method to the String class of .NET.

// the container is a static class and the method uses the 'this' keyword within the first parameter.
// the additional method will be bolted on to the type listed in the first parameter after the 'this'.
public static class GroovyLike
{
    public static void Execute(this string s)
    {
        System.Diagnostics.Process.Start(s);
    }
}

//and then using it
public class Util
{
    public void LaunchExcel()
    {
        "excel.exe".Execute()
    }
}
 

For more info see:
MSDN - Extension Methods (C# Programming Guide)
A Set of Useful Extension Methods for DateTime
Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5
Turn DataTable object into a styled HTML table using extension methods in C#

bookmark with Diggbookmark with StumbleUponbookmark with Technoratibookmark with Redditbookmark with Delicousbookmark with NewsVineDZone Itbookmark with Furl