Quickly introduce using statements and try-catch blocks

Skip to end of metadata
Go to start of metadata

Apart from being able to generate blocks of code with live templates, ReSharper also lets you surround existing code with additional statements, such as try-catch or using statements.

To show the surround menu, simply select the block of code and press Ctrl+E, Ctrl+U (if using VS layout). This will pop up a menu of available surround statements:

Now, you can simply press one of the shortcut keys on the right to surround the code. For example, to surround the code with a try-catch, you can press 8 on your keyboard. ReSharper will generate the default code stub and allow you to configure any optional values:

In this menu, you can also press More… in order to see a total list of available surround templates and pick which ones are added to the quicklist (the list you get when you fire up the command):

  • No labels