December 4th, 2009Most Amazing ReFactor Using ReSharper EAP 5.0 I’ve Seen!
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.
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!









December 4th, 2009 at 1:40 pm
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!
December 5th, 2009 at 3:35 am
That is pretty impressive!
December 8th, 2009 at 1:10 pm
Can’t disagree. And there are even cooler features than this one.
December 15th, 2009 at 3:44 am
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?
February 25th, 2011 at 7:04 am
I didn’t know that is possible to convert into LinkQ-Expression in this way. This seems to be most effective way to obtain good results in a very simple way. Thank you. I’ve didn’t hear until now about this trick.
March 4th, 2011 at 5:54 am
The LinkQ-Expression can be used in this way if you know very well the code. I am interested in using of this code for your own projects. This article helps me to follow the same rules as you, with the same results.
August 29th, 2011 at 3:13 am
very good job I did not know exactly how it works, thanks