Daily Archives: April 8, 2009

Found the first thing in Refactor! that I don’t like

So far, the latest versions of CodeRush and Refactor! have been pretty impressive.  Unfortunately, I’ve just found the first bit of behaviour that I’m not too keen on.  Take the following snippet…

foreach (MyProvider provider in lps)
{
  Console.WriteLine(provider.AccountStatus);
}

  
Fair enough. Old Skool way to write a loop, but nothing too extreme. Refactor! prompted me that I may like to “Introduce ForEach Action”. I decided to take its advice, and it turned the routine into

Array.ForEach(lps,
delegate(MyProvider provider)
{
  Console.WriteLine(provider.AccountStatus);
});

 
OK, still does the same thing, but I hate the way it looks. It’s kind of a half-way house between old-skool and lambda. This was even pointed out by Refactor! – it suggested that I “Compress to Lambda Expression”.

So I did. The result was much more pleasing.

Array.ForEach(lps, provider => Console.WriteLine(provider.AccountStatus));

Lovely.

All I’d like to see in Refactor! is the ability to go from the first snippet the the last without having to take a detour through Uglytown. Is that too much to ask?