Saving keystrokes with LiveTemplates

One of the cool features Resharper has is to allow you to define live code templates, i.e. snippets that you can interact with. Say for example you continuously type:


   1: var customerServices = new Mock<ICustomerServices>();


each time you want to mock out a service. You could shorten this to only typing:



and here’s how:

1. Resharper -> Live Templates

2. Under User Templates, create a new one

3. Type in: var $name$ = var Mock<I$interface$>();


4. Give it the ShortCut name of “mock” (or whatever you please)

5. On the right-side of the Window, click on the Choose Macro on the name entry


6. Pick Constant Value and close the dialog


7. Click on the Constant Value again on the right-hand side


8. Enter a value, for example mockObject


9. Repeat the same process (Choose Macro) for the interface entry, but this type choose the following option:


10. Set the variable by clicking on another variable link:


11. Choose the variable name


12. Close the editor and you’re done. Now watch how it works


Obviously this is just a simple example, but you can see how powerful Live Templates can be.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s