JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 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, JetBrains Rider lets you specify a new name and invert all its usages, that is if you refactor private bool isEnabled; to private bool isDisabled;, JetBrains Rider will make sure that, for example, if(isEnabled) becomes if(!isDisabled) everywhere.

If you apply this refactoring to a boolean method, JetBrains Rider 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: