Well I thought I would kick off the blog with this handy generic method to parse enum strings.

public static T ParseEnum<T>(string enumText)  
{ 
    return (T) Enum.Parse(typeof (T), enumText); 
}

So lets compare the usage generic vs. non generic

public enum Vehicles  
{
    Bus,
    Car,
    Bike
}

public void TestEnumParse  
{
    //Create a enum value
    Vehicles myVehicleEnum = Vehicles.Car;

    //Get the enum string
    string vehicleString = myVehicleEnum.ToString();

    //Convert the string to an enum using non generic method
    Vehicles nonGenericParse = (Vehicles) Enum.Parse(typeof (Vehicles), vehicleString);

    //Convert the string to an enum using the generic method
    Vehicles genericParse = Helpers.ParseEnum<Vehicles>(vehicleString);
}

You could create ParseEnum as a string extension method however I’m not sure its a good idea to have a parse enum method on every string created. I use the generic method from a static helper class and I think its a much cleaner way of converting the enum string.