Home > Coding Helpers, Selection > Inverting a code block into its opposite using CodeRush Selection Inversion

Inverting a code block into its opposite using CodeRush Selection Inversion

October 24th, 2011

The Selection Inversion feature of CodeRush Pro allows you to invert the selected code block to the essential opposite. For example, it can invert assignments so its expression assigns the left side; for loops, so they are iterated in a different order; type cast expression, so an ‘as’ operator expression is converted into an explicit typecast, etc.

Selecting the ‘for’ loop in the following code:

CodeRush Selection Inversion sample code

and applying Selection Inversion will yield into the following code:

CodeRush Selection Inversion code result

The feature is based on the regular expressions and easily customizable. You can add your own inverted regular expressions on the Inversion options page. Also, there’s is a special DXCore component used to extend the feature called SelectionInversionExtension that adds custom intelligent selection inversions.

To apply the Selection Inversion, you can utilize the following techniques:

  • Use the default Ctrl+Shift+I shortcut: select a block of code that corresponds to one of the existing selection inversion expressions and press the shortcut to invert it.
  • Use the Invert Selection code provider: select a block of code and perform the code provider to invert the selected text:

Performing CodeRush Invert Selection code provider

See how you can customize and define your own inversion items on the Selection Inversion options page.

—–
Products: CodeRush Pro
Versions: 11.1 and up
VS IDEs: any
Updated: Oct/24/2011
ID: C136

Similar Posts: