ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Invert Boolean refactoring

Last modified: 21 July 2022

ReSharper | Refactor | Invert Boolean…

To assign a shortcut, go to Tools | Options | Environment | Keyboard and find the ReSharper_InvertBool command.

This refactoring allows you to automatically modify a boolean member so that its value is inverted. If you apply this refactoring to a boolean field or a property, ReSharper lets you specify a new name and invert all its usages, that is if you refactor private bool isEnabled; to private bool isDisabled;, ReSharper will make sure that, for example, if(isEnabled) becomes if(!isDisabled) everywhere.

If you apply this refactoring to a boolean method, ReSharper lets you choose whether to invert its internal logic, usages, or both.

In the example below, we use this refactoring to invert the IsEven method. We specify a new name IsOdd and choose to invert both the internal logic and usages:

This feature is supported in the following languages and technologies: