Most Amazing ReFactor Using ReSharper EAP 5.0 I’ve Seen!
Friday 4 December 2009 @ 11:27 am

 

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!

Comments (4) - Posted in LINQ, ReSharper  




4 Responses to “Most Amazing ReFactor Using ReSharper EAP 5.0 I’ve Seen!”

  1. Ryan Anderson Says:

    Cool!
    Been using Resharper for a while now as well, and it has always blown my mind how much I learn about coding from the tool. Resharper is fantastic learning tool for me!

  2. rtpHarry Says:

    That is pretty impressive!

  3. Arnis L. Says:

    Can’t disagree. And there are even cooler features than this one.

  4. cultural festivals Says:

    Say you have a line drawing of a cube, drawn with a computer and with lines appearing pixelated/boxy. How could you use Photoshop to remove the pixelation effect and instead make the lines look completely smooth? what do you say?

Leave a Reply