I had some verbose code:
private bool AnyUnselectedCombox()
{
bool anyUnselected = false;
foreach (Control c in this.Controls)
{
if (c is ComboBox)
{
if ((c as ComboBox).SelectedIndex == -1)
{
anyUnselected = true;
break;
}
}
}
return anyUnselected;
}
...that Resharper offered to elegantize with a LINQ expression like so:
return this.Controls.OfType<ComboBox>().Any(c => (c as ComboBox).SelectedIndex == -1);
...but the subsequent Resharper inspection says about the code it generated (above): "Type cast is redundant" (referring to the "c as ComboBox" part), so that it ends up as:
return this.Controls.OfType<ComboBox>().Any(c => c.SelectedIndex == -1);
Shouldn't Resharper generate Resharper-approved code? Or does it simply sometimes need two passes for it to fully "gird up its loins"?
ReSharper helps instantly get to any code in a solution, no matter how large the solution is. It can also navigate you from any symbol to its related code such as implementations of a given interface, extension methods of a class, or usages of a field.
Stale caches If you have recently updated ReSharper and observe performance degradation with solutions that were opened with previous versions, you can attempt to speed thing up by clearing the ReSharper caches and deleting the solution .
Yes, sometimes ReSharper corrects itself, requiring a second pass to get it "just right". I've always assumed it uses certain "safe templates" to do the conversion and in some cases some parts of the safe transformation aren't really needed.
All versions of the code are correct and equivalent though, the first "pass" is converting to Linq and the second "pass" removes some redundant code that the Linq transformation added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With