JetBrains Rider 2021.3 Help

Predefined Surround Templates for C#

This topic lists all predefined surround templates for C# in JetBrains Rider 2021.3. For more information about surround templates, see Surround code fragments with templates

Template

Details

()

Surround the selection with parentheses

Scope C# 2.0+, C++ expressions

Body

($SELECTION$$END$)

Parameters

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

{}

Surround the selection with braces

Scope C# 2.0+, C++ statements

Body

{ $SELECTION$$END$ }

Parameters

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

foreach

foreach block

Scope C# 2.0+ statements

Body

foreach ($TYPE$ $VARIABLE$ in $COLLECTION$) { $SELECTION$$END$ }

Parameters

  • COLLECTION - Show basic code completion list at the point where the variable is evaluated

  • TYPE - Suggest type for a new variable declared in the template

  • VARIABLE - When executed in variable declaration (where variable name should stand), suggests name for the variable.

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

for

Simple "for" loop

Scope C# 2.0+ statements

Body

for (int $INDEX$ = 0; $INDEX$ < $UPPER$; $INDEX$++) { $SELECTION$$END$ }

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point.

  • UPPER - no macro

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

#if

Scope C# 2.0+ except strings, at line start

Body

#if $expression$ $SELECTION$$END$ #endif

Parameters

  • expression - Evaluates to the specified constant value.

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

#region

Surround the selection with a region

Scope C# 2.0+ except strings, at line start

Body

#region $name$ $SELECTION$$END$ #endregion

Parameters

  • name - Evaluates to the specified constant value.

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

namespace

Add a namespace to the selected code

Scope C# 2.0+ types and namespaces

Body

namespace $name$ { $END$$SELECTION$ }

Parameters

  • name - Evaluates to the specified constant value.

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

tryf

try finally

Scope C# 2.0+ statements

Body

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

Parameters

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

try

try catch

Scope C# 2.0+ statements

Body

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

Parameters

  • EXCEPTION - Evaluates to the specified constant value.

  • EX_NAME - When executed in variable declaration (where variable name should stand), suggests name for the variable.

  • SELECTION - The text selected by the user before invoking the template.

while

while loop

Scope C# 2.0+ statements

Body

while ($expression$) { $SELECTION$$END$ }

Parameters

  • expression - Show basic code completion list at the point where the variable is evaluated

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

do

do...while loop

Scope C# 2.0+ statements

Body

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

Parameters

  • expression - Suggests variables of the specified type.

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

if

if statement

Scope C# 2.0+ statements

Body

if ($expr$) { $SELECTION$$END$ }

Parameters

  • expr - Show basic code completion list at the point where the variable is evaluated

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

lock

lock statement

Scope C# 2.0+ statements

Body

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

Parameters

  • expression - Suggests variables of the specified type.

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

using

using statement

Scope C# 2.0+ statements

Body

using($resource$) { $SELECTION$$END$ }

Parameters

  • resource - Show basic code completion list at the point where the variable is evaluated

  • SELECTION - The text selected by the user before invoking the template.

  • END - The caret position after the template is applied.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

cast

Cast the selection to a specific type

Scope C# 2.0+ expressions

Body

(($TYPE$)$SELECTION$)

Parameters

  • TYPE - Guess type expected at this point

  • SELECTION - The text selected by the user before invoking the template.

Before expansion

JetBrains Rider: Live templates
After expansion
JetBrains Rider: Live templates

Last modified: 07 April 2022