ReSharper allows you to quickly change the order of code elements by moving them up or down. In particular, you can:
- Type members
- Move class, interface, structure, enum members up and down
- Move base types for classes, interfaces, structures and methods
- Move type parameters of classes, interfaces, structures and methods
- Move type parameter constraints
- Move attributes
- Move parameter declarations of method, indexer, operator, delegate
- Move accessors of properties
- Move statements within a block
- Move statements out of or into a block
- Move embedded statement(s) within if-else clauses
- Move embedded statement(s) from one clause of if-else statement to another one
- Move nested if-else statement
- Move switch section within a switch statement
- Move statement(s) within a switch section, from one switch section to another, out of a switch statement
- Move catch clauses within a try-catch statement
- Move local variable declarations within the local scope
- Move local constant declarations within the local scope
- Type and namespace declarations
- Move line and c-style comments up and down
#regionblock up and down, out of and into another
#regiondirective and its name
- Expressions and references
- Move operands of binary and assignment expressions
- Move parameters in invocations, indexes, object creation expressions, anonymous delegates, lambdas
- Move elements in collection and array initializers
- Move clauses in query expressions
- Move type arguments in type and method references
- In text files
- Move a line where the caret is placed
- Move selection
You should move code elements at your own risk since ReSharper neither performs any validity checks nor fixes any references.
For full-fledged refactorings that solve related tasks, see
- Place the caret at a code element that should be moved.
- Do one of the following:
- On the main menu, choose ReSharper | Edit | Rearrange Code. Depending on the caret position some menu items might not be available. Choose one of the available menu items in order to move the code element to the corresponding direction.
- Press Ctrl+Shift+Alt. ReSharper displays a tooltip that shows what code elements in what ways can be moved. Press the appropriate arrow key.
NoteDepending on the caret position you are prompted to move expressions within a statement or the whole statement or statements within the current statement.
ReSharper 6 takes into account blank lines, now they are not removed, but moved with corresponding code elements.