ReSharper 8.0 Web Help

ReSharper | Templates Explorer | Surround Templates | C#

C#

ReSharper comes with a number of predefined surround templates. You can use them "as is" or customize according to your individual requirements and programming style.

Some templates are parameterized, requiring that you fill in some parameters after the template code is inserted.

Two parameters specified in preview listings are common for most templates:

  • $SELECTION$ specifies the position of previously selected code within an applied template.
  • $END$ denotes the position of the caret after a template is applied.
Template name Description
#if..#endif

Go to top

Purpose
Delimits a selection with a pair of preprocessor directives. #if and #endif.

#if $END$
    $SELECTION$
#endif

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - position of the caret after applying the template.

#region

Go to top

Purpose
Surrounds a selection with a region.

#region $END$
    $SELECTION$
#endregion

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - position where ReSharper puts the caret after applying the template, to help you specify the name of your new region.

()

Go to top

Purpose
Surrounds a selection with a pair of parentheses.

($SELECTION$$END$)

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - having applied the template, ReSharper puts the caret after the selected block of code.

{}

Go to top

Purpose
Surrounds a selection with a pair of braces.

{
$SELECTION$$END$
}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - having applied the template, ReSharper puts the caret after the selected block of code.

cast

Go to top

Purpose
Casts a selection to a specified type.

(($TYPE$)$SELECTION$)

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • TYPE - type to cast the selection to.

do..while

Go to top

Purpose
Puts a selection into a do..while statement block.

do{$SELECTION$}while($END$);

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - condition where ReSharper puts the caret after applying the template.

for

Go to top

Purpose
Puts a selection into a for statement block.

for($END$){$SELECTION$}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - the position where ReSharper puts the caret after applying the template, so that you can easily specify the condition.

if

Go to top

Purpose
Puts a selection into an if statement block.

if($END$){$SELECTION$}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - that's where ReSharper puts the caret after applying the template, to help you define condition.

if..else

Go to top

Purpose
Integrates a selection into the if statement block of an if..else conditional statement.

if ($COND$)
{
    $SELECTION$
}
else
{
    $END$
 }

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • COND - a user-defined condition that allows execution of the if statement block.
  • END - body of the else statement block, where ReSharper places the caret after applying the template, so that you can fill this block with code.

lock

Go to top

Purpose
Integrates a selection into a lock statement.

lock ($LOCK$)
{
$SELECTION$$END$
}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - position of the caret after applying the template.
  • LOCK - type that you intend to lock.

namespace

Go to top

Purpose
Adds a namespace to selected code.

namespace $NAME$ {$END$$SELECTION$}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - position of the caret after applying the template.
  • NAME - name of the appropriate namespace.

String.Format

Go to top

Purpose
Integrates a selected format string into a String.Format method call.

string.Format($SELECTION$, $END$);

Before expansion

After expansion

Parameters

  • SELECTION - a selected format string.
  • END - position of the caret after the template is applied, allowing you to specify variables for formatting.

try..catch

Go to top

Purpose
Puts a selection into the try block of a try..catch statement.

try {$SELECTION$} catch ($EXCEPTION$ $EX_NAME$)
{
    $SELSTART$System.Console.WriteLine($EX_NAME$);$SELEND$
}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • EXCEPTION - type of exception to be caught.
  • EX_NAME - name of variable (s by default) that holds the specified exception.
  • SELSTART - start of selection that you can easily make by tabbing through this template's parameters after it is applied; this selection makes it easier to replace default code in the catch block.
  • SELEND - end of selection in the catch block (see SELSTART).

try..finally

Go to top

Purpose
Puts a selection into the try block of a try..finally statement.

try {$SELECTION$} finally
{
    $END$
}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - position of the caret after applying the template.

using

Go to top

Purpose
Puts a selection into a using statement.

using($END$){$SELECTION$}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - position of the caret after applying the template.

while

Go to top

Purpose
Puts a selection into a while statement block.

while($END$){$SELECTION$}

Before expansion

After expansion

Parameters

  • SELECTION - a selected block of code.
  • END - the position where ReSharper puts the caret after applying the template, so that you can specify the condition right away.

See Also

Reference