I’m constantly amazed by the insightfulness of ReSharper’s suggested refactorings (ReSharper is a Visual Studio Addin from JetBrains I use with C#). Today, I’ve been working on a threading problem where I’m getting crashes based on what seems like not proper locking across threads (they usually show up as some type of ugly update object or enum error).
My code starts like this:
public static List<DbProgressReport> DbProgressReportProperty { get; set; }
(more…)
In this post, we’ll take a straight forward procedure based set of code and convert it to LINQ using a ReSharper from JetBrains suggestion. I’ve found that in general, when I do things with foreach syntax, there is often a better way in Linq to do this. The better does not jump out at me sometimes, however with ReSharper, it is often a button click away.
(more…)
So, if you are like me, it’s easy to make mistakes on whether to use && or || when combining variables on if statements. I hate to just start nesting if statements because the code gets bulky, but if not, I have to think three times about whether I got it right.
So, Here comes Resharper for c# from Jetbrains. Simply write the if statement nested as follows:
(more…)
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;
}
(more…)
Well, now I know. Here is an example of some code I just wrote:
if (doDeficitCalc)
{
throw
new ApplicationException("Need to implement deficit weight rating");
}
else
{
// Linear interpolation from top of range to bottom for speed
double x1 = rateBreakList[0];
double x2 = rateBreakList[rateBreakList.Count - 1];
double y1 = rateList[0];
double y2 = rateList[rateList.Count - 1];
double frac = weight/(x2 - x1);
double yResult = y1 + (frac*(y2 - y1));
retWeight = yResult;
}
ReSharper correctly warns me that the else statement is redundant as shown below:
(more…)