Skip to content

Most Amazing ReFactor Using ReSharper EAP 5.0 I’ve Seen!

Updated: at 02:12 PM

 

This one is just to amazing to not blog about.  I’ve been a die heart ReSharper user for quite a while and recently have started using their early access versions.  Primarily because they seem to have added a lot of LINQ support which I use heavily now.  I had the following code before the refactor.  I have to admit, it’s a little .Net 1.1/2.0 ish, but what can I say, I’m a production coder and it did the job.

private static int GetTransitTime(string parcelToCheck)
{
    int transitTime = 0;
    foreach (var parcelSCAC in Constant.UPS_SCAC_MAP)
    {
        if (parcelSCAC.Key.Equals(parcelToCheck))
        {
            transitTime = Constant.UPS_TRANSIT_TIME[parcelSCAC.Value];
            break;
        }
    }
    return transitTime;
}

I noticed the little helper icon making a suggestion (ReSharper Icon that is) so I hovered over to see what it wanted.

 

image

And, I chose what it suggested, and wow!  check this out.   The way I should have coded it in the first place.

private static int GetTransitTime(string parcelToCheck)
{
    return (from parcelSCAC in Constant.UPS_SCAC_MAP
            where parcelSCAC.Key.Equals(parcelToCheck)
            select Constant.UPS_TRANSIT_TIME[parcelSCAC.Value]).FirstOrDefault();
}

All I can say is I love it.   If you don’t use ReSharper, drop what you are doing and go out and buy it!

Check out the ORM (Object Relational Mapper) PRISMA. The database access method I use in all my projects