News


Add to Technorati Favorites

My Stats

  • Posts - 51
  • Comments - 209
  • Trackbacks - 20

Twitter












Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


Image Galleries


Blogs I read


Company Links


Fun Stuff


Kansas City User Groups


My CMS Projects



Just stumbled across some pretty cool functionality with Jet Brains ReSharper 4.0 (you may already be familiar with it, but who cares, it’s still cool!)

 

Basically, ReSharper has a Surround With tool that allows you to surround a selection of code with… more code. It comes with a bunch of predefined templates, like if..else, using, while, try..catch blocks, but you can edit existing templates and also create and organize your own custom templates.

To get to the Templates Explorer, select ReSharper > Live Templates… from the file menu. Select the Surround Templates tab. Once you’re in there, click on the New Template icon and a new File will open in the IDE, and filled by default with the text $SELECTION$. This is the code selection that will be wrapped when your template is applied. Below is a cap of a sample wrapper with some sample template code.

 

resharper_templates_explorer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

To apply the template, highlight your code selection

 

resharper_pre_change

 

 

 

 

 

 

Select ReSharper > Code > Surround With… from the File menu (or CTRL + E, U).

 

resharper_wrap_menu

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Choose More… from the menu. Find your  template in the dialog and click OK.

 

resharper_find_template

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

When your template is applied, your selection will be replaced with the wrapped text, like below.

 

resharper_post_change

 

 

 

 

 

 

 

This is just the basic stuff. You can categorize your templates, choose which language they will apply to, add them to the quicklist (so they get assigned a quick key), and a whole bunch of other stuff that can be found on the ReSharper help pages.

 


posted @ Thursday, October 15, 2009 6:00 PM |

Comments

Gravatar # re: ReSharper | Surround With
Posted by Garry Pilkington on 10/19/2009 4:19 AM
Thanks for this, that is a really handy tip. I will commit CTRL + E,U to memory now.
Gravatar # re: ReSharper | Surround With
Posted by Jack on 10/20/2009 4:08 AM
nice, very powerful
Gravatar # re: ReSharper | Surround With
Posted by Bodie on 10/20/2009 9:14 AM
This is a handy feature. I just set up a template in Resharper yesterday to add the boilerplate for a unit test. Could I live without Resharper? Yes. Would I choose to? No Sa!
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: