Code Templates

Live Templates

Live templates are ReSharper's far more intelligent version of Visual Studio's code snippets. To apply a live template, just type a template abbreviation, and press Tab in the completion list to expand the template. After that, use Enter or Tab to navigate through template variables. (If you use Visual Studio's native code completion, press Ctrl+J to display the list of available live templates to expand a template.) Unlike code snippets, ReSharper can predict from the context which variables, fields, and types can be used in corresponding templates. In most cases you don't need to type anything yourself. Just choose from a list of suggested values.
ReSharper provides more than 20 live templates for C#, 17 live templates for VB.NET and 3 live templates for XML. The list includes templates for iterating through collections, writing assertion methods, creating new arrays, outputting values, coding LINQ queries and generating auto-properties, and more.

to the top

'Surround With' Templates

'Surround with' templates are used to quickly enclose an expression, a single statement, or an arbitrary block of code with if/else, try/catch or other code constructs. ReSharper intelligently reformats the code, adjusts the selection, and/or repositions the caret as specified by the template.
To surround a piece of code, select it and press Ctrl+Alt+J.

to the top

File Templates

ReSharper lets you add new files to your project with predefined code fragments already generated in them. For example, you can create a new file with a class declaration, an interface, struct declaration, and so on. To choose from the list of file templates, click a node in Visual Studio's Solution Explorer, and press Alt+Ins.

to the top

Customizing, Configuring and Sharing Templates

You can create your own templates and modify those that come bundled with ReSharper.
For editing templates, ReSharper 4.0 introduces Template Editor — a new user interface that opens in a separate Visual Studio code pane, allowing you to switch between your code and your template editing environment to make real-world testing of templates faster.

For managing templates, you can use Templates Explorer that you can call by choosing Live Templates on the ReSharper menu:

Once defined, any template can be easily shared among team members in two ways using the Templates Explorer.

to the top

Shared Solution Templates folder

You and your team members can use this folder to store shared templates designed for use with any particular solution. Templates placed in the folder will be accessible to anyone who opens the current solution.

to the top

Mounted File Storage

Templates can also be shared among a group of developers via Mounted File Storage. First, team members mount file storage where the file contains templates designed for common use by the team and is stored in a shared network location. Templates contained in the mounted file are updated from and to the file whenever the solution is opened or closed. Any changes made to the file are automatically made available to all other developers.

to the top