ReSharper Web Help

ReSharper | Templates Explorer | Surround Templates| VB.NET

VB.net

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
CType

Go to top

Purpose
Transforms selection into the first parameter of the CType() function, which is used to explicitly convert VB.NET types.

CType($SELECTION$, $TYPE$)

Before expansion

After expansion

Parameters

  • SELECTION - selected variable.
  • TYPE - type to cast to.

DirectCast

Go to top

Purpose
Transforms selection into the first parameter of the DirectCast function as an alternative way to perform type casts.

DirectCast($SELECTION$, $TYPE$)

Before expansion

After expansion

Parameters

  • SELECTION - selected variable.
  • TYPE - type to cast to.

If

Go to top

Purpose
Puts selection into the statement block following Then in an If-Then construct.

If $END$ Then
    $SELECTION$
End If

Before expansion

After expansion

Parameters

  • SELECTION - selected code.
  • END - position of the caret after applying the template, helping you specify a condition.

If..Else

Go to top

Purpose
Puts selection into the statement block following Then in an If-Then-Else construct.

If $COND$ Then
    $SELECTION$
Else
    $END$
End If

Before expansion

After expansion

Parameters

  • SELECTION - selected code.
  • COND - condition of the construct.
  • END - position of the caret after applying the template, helping you insert code into the Else block.

namespace

Go to top

Purpose
Wraps selection into a namespace.

Namespace $END$
$SELECTION$
End Namespace

Before expansion

After expansion

Parameters

  • SELECTION - selected code.
  • END - position of the caret after applying the template, helping you specify an identifier for the new namespace.

SyncLock

Go to top

Purpose
Transforms selection into the statement block of a SyncLock statement.

SyncLock $END$
    $SELECTION$
End SyncLock

Before expansion

After expansion

Parameters

  • SELECTION - selected block of statements.
  • END - position of the caret after applying the template, helping you type an expression to be evaluated.
In some cases, you might want to apply this template without making a selection.

TryCast

Go to top

Purpose
Wraps selection with a cast expression that doesn't throw exceptions.

TryCast($SELECTION$, $TYPE$)

Before expansion

After expansion

Parameters

  • SELECTION - selected variable.
  • TYPE - type to cast to.

Using

Go to top

Purpose
Puts selection into a using statement.

Using $END$
    $SELECTION$
End Using

Before expansion

After expansion

Parameters

  • SELECTION - selected code.
  • END - position of the caret after applying the template, helping you specify resources that should be obtained with the using statement.

See Also

Reference