ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Invert Boolean refactoring

Last modified: 23 September 2024

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: