DSP2017

ReSharper – all you need is… refactoring & code templates! – part 2

Ladies and gentlemen – the second post about ReSharper! This time, let’s focus on refactoring, auto-generation of code and some smart ‘helpers’.

Assistance & helpers

  • Ctrl + D – duplicates the line where the cursor is.
  • Ctrl + Shift + F1 – opens small window with documentation of the class/method/type that the caret is ‘touching’. Below – documentation for ‘string’ type .
  • Ctrl + Shift + V – opens history of the things you copied to your clipboard. I’ve always wanted to have it! Just look at this:

 

Suggestions, refactoring and code auto-generating:

  • Alt + Enter – opens context menu with suggestions of changes in the line where caret is.
  • Ctrl + Shift + R – refactor suggestions, like the one below:
    My favorite options are:
  1. Introduce Field – opens the below window, so we can choose the way we want a field to be added.
    Let’s assume that we have a ‘starter code’ like this:

Below I show you the changes in code that all the 3 options make.

Current member:

Field initializer:

Constructor(s):

2. Introduce Variable – it will change the ‘starter code’ like this:

3. Introduce Parameter – I love it! It not only adds a parameter to the method:

… but also puts appropriate values everywhere we use this method!

  • Alt + Insert – pressed when caret is inside a class, interface etc declaration will open menu with some useful option (ex. adding constructor, properties that base on some existing variable, overriding members of base type and so on).

 

Code templates – my beloved!

  •  Ctrl + E + L – shows the below menu where you can choose the desired snippet… and then fill only necessary fields (use TAB to move caret from one highlighted text to the other):
  • Ctrl + E + U – typed over selected text will surround it with a construction like ‘if’, ‘while’ and so one… Like in the pic below:
Featured image Angelina Litvin.

Share this:

  • Pingback: dotnetomaniak.pl()

  • . R41L.

    Don’t forget to mention postfix templates – r0x #1 R# killer feature