Tim Van Wassenhove

Passionate geek, interested in Technology. Proud father of two

03 Jul 2010

Sometimes you can write it better than Resharper

Here is a real-life example of when people are much better expressing intent than a tool: Consider the following code from a typical Silverlight Navigation application

foreach (UIElement child in LinksStackPanel.Children)
{
	var hb = child as HyperlinkButton;
	if (hb != null && hb.NavigateUri != null)
	{ .. }
}

Resharper proposed to write this as following

foreach (var hb in LinksStackPanel.Children
	.Select(child => child as HyperlinkButton)
	.Where(hb => hb != null && hb.NavigateUri != null))
	{ .. }

Here is what i wrote instead

foreach (var hb in LinksStackPanel.Children
	.OfType<hyperlinkButton>()
	.Where(hb => hb.NavigateUri != null))
	{ .. }