Invert Boolean refactoring
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, i.e. if you refactor
private bool isEnabled; to
private bool isDisabled;, ReSharper will make sure that, for example,
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:
To invert a boolean method
- Place the caret at the declaration or a usage of a boolean member in the editor, or select it in the File Structure Window.
- Do one of the following:
- If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
This feature is supported in the following languages/technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.