Thursday, September 25, 2008

Using Smart Generate

I am just amazed at how well Smart Generate works.

Here is an example:

Whenever I write use a string, that is visible to the user, I need to run it through a Translate.Text method, e.g:


output.Write(Translate.Text("Visible output"));


However writing the call the Translate.Text is tedious, so I want to put that in Smart Generate.

First I write the statement with out the Translate.Text call.


output.Write("Visible output");


I place the caret on top of the string literal, and press Shift+Enter, which brings up the Smart Generate menu.

From the menu I select "Create Live Template" and then "Surround String Expression".

ReSharpers Live Template Editor opens and I name the Live Template "Translate string". The code of the Live template is:


Translate.Text($SELECTION$)


Save the Live Template and return to original code.

Press Shift+Enter to show the Smart Generate menu and select "Translate string".

And bingo, I have:


output.Write(Translate.Text("Visible output"));


Never have to write another call to Translate.Text manually again.

Big smile!

No comments: