private static void MyMethod(MyClass1 searcher, MyClass2 oldItem) { if (oldItem != null && searcher != null) { try { // Some operation } catch (Exception e) { // Some logging code } } }
When I do the suggested invert if to remove nesting, it generates the following:
if (oldItem == null || searcher == null) { } else { try { // My operation } catch (Exception e) { // My logging } }
when it should generate:
if (oldItem == null || searcher == null) return; try { // My operation } catch (Exception e) { // My logging }