December 19th, 2009Another Cool Resharper Refactoring
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:
if (_instance._meta == null) { if (DataContextLazyLoad) { AssignAllDataContexts.Run(); } }
Then, resharper will give you the following suggestion about merging if’s:
Chose “Merge two if’s”
And, this is what you get:
if (_instance._meta == null && DataContextLazyLoad) { AssignAllDataContexts.Run(); }
OK, granted, this one was pretty simple, but think about when it gets more complicated. Hard not to love this product.









December 20th, 2009 at 5:35 am
I’m more a fan of the ‘invert if’ refactoring, which in this case would lead to the following code:
if (_instance._meta == null) return;
if (!DataContextLazyLoad) return;
AssignAllDataContexts.Run();