ReSharper Web Help

ReSharper | Live Templates | Live Templates | Predefined Templates | C# | Other

C#

Other

This group contains non-categorized templates. Templates for creating arrays, declaring public variables and creating empty methods are provided here, among others.

Template name Description
asrt

Go to top

Purpose
This template calls the Debug.Assert method, which is used for debugging purposes. After the template expanded, the caret moves between the parentheses so that you can specify a condition.

System.Diagnostics.Debug.Assert($END$);

Before expansion
asrt (before)
After expansion
asrt (after)

Parameters

  • END - asserted condition and an optional string message to be displayed if the condition becomes false.

ear

Go to top

Purpose
Generates a code fragment that creates an empty array.

$TYPE$[] $NAME$ = new $TYPE$[] {};

Before expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ear__before.png
After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ear__after.png

Parameters

  • TYPE - type of array elements.
  • NAME - name of array variable (ReSharper comes up with some suggestions based on the TYPE chosen, for example, it substitutes NAME with ints for an integer array).

from

Go to top

Purpose
Starts a LINQ query.

from $VAR$ in $COLLECTION$ $END$

Before expansion
from (before)
After expansion
from (after)

Parameters

  • VAR - name of variable to store the current collection item.
  • COLLECTION - collection that the query is performed upon.

hal

Go to top

Purpose
Inserts the ActionLink() method call within ASP.NET MVC view.

Html.ActionLink("$TEXT$", "$ACTION$", "$CONTROLLER$")

Before expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__hal__before.png
After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__hal__after.png

Parameters

  • TEXT - action name.
  • ACTION - ASP.NET MVC action method name.
  • CONTROLLER - ASP.NET MVC controller class name.

join

Go to top

Purpose
Refers to an secondary collection in a LINQ query.

join $NAME$ in $COL$ on $EXPR1$ equals $EXPR2$ $END$

Before expansion
join (before)
After expansion
join (after)

Parameters

  • NAME - name of variable that holds a current item in the secondary collection.
  • COL - secondary collection.
  • EXPR1 - key field of a current item from the primary collection.
  • EXPR2 - key field of a current item from the secondary collection.
  • END - position of the caret after applying the template.

out

Go to top

Purpose
Outputs a string.

System.Console.Out.WriteLine("$END$");

Before expansion
out (before)
After expansion
out (after)

Parameters

  • END - an arbitrary string.

outv

Go to top

Purpose
Outputs the value of a variable defined in the current scope.

System.Console.Out.WriteLine("$EXPR$ = {0}", $EXPR$);

Before expansion
outv (before)
After expansion
outv (after)

Parameters

  • EXPR - name of target variable.
ReSharper automatically suggests a list of all variables in the current scope and, by default, selects the most recently declared one. The descriptive text string (s = in the example above) is automatically synchronized with the name of the selected variable.

pci

Go to top

Purpose
Declares an integer constant.

public const int

Before expansion
pci (before)
After expansion
pci (after)

pcs

Go to top

Purpose
Declares a constant string.

public const string

Before expansion
pcs (before)
After expansion
pcs (after)

prop

Go to top

Purpose
Generates an auto-property.

public $TYPE$ $NAME$ { get; set; }

Before expansion
prop (before)
After expansion
prop (after)

Parameters

  • TYPE - property type.
  • NAME - property name.

psr

Go to top

Purpose
Generates a static read-only field.

public static readonly

Before expansion
psr (before)
After expansion
psr (after)

psvm

Go to top

Purpose
Generates the Main() application method.

public static void Main (string[] args)
{
    $END$
}

Before expansion
psvm (before)
After expansion
psvm (after)

Parameters

  • END - method body.

rta

Go to top

Purpose
Inserts the RedirectToAction() method call in ASP.NET MVC controller.

RedirectToAction("$ACTION$", "$CONTROLLER$")

Before expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__rta__before.png
After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__rta__after.png

Parameters

  • ACTION - ASP.NET MVC action method name.
  • CONTROLLER - ASP.NET MVC controller class name.

sfc

Go to top

Purpose
Generates a code construct to cast variables in a safe manner.

$VARTYPE$ $VAR$ = $VAR1$ as $TYPE$;
if ($VAR$ != null)
{
    $END$
}

Before expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__sfc__before.png
After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__sfc__after.png

Parameters

  • VARTYPE - target variable type.
  • VAR - name of target variable.
  • VAR1 - name of source variable.
  • TYPE - target variable type (substituted by ReSharper).
  • END - loop body.

thr

Go to top

Purpose
Throws an exception.

throw new

Before expansion
thr (before)
After expansion
thr (after)

toar

Go to top

Purpose
Generates a code fragment that copies the elements of System.Collections.ArrayList to an array using the ToArray() method.

($TYPE$[])$ARRAYLIST$.ToArray(typeof($TYPE$))

Before expansion
toar (before)
After expansion
toar (after)

Parameters

  • TYPE - type of target array (ReSharper guesses the returned element type, as in the example above (char)).
  • ARRAYLIST - an ArrayList collection (ReSharper provides the list of all such collections available in the scope, as in the example above).
This template is most efficiently used where the required element type can be determined from the context. After parameters are specified, the caret is placed at the end of the statement.

ua

Go to top

Purpose
Inserts the Action() method call in ASP.NET MVC view or controller.

Url.Action("$ACTION$", "$CONTROLLER$")

Before expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ua__before.png
After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ua__after.png

Parameters

  • ACTION - ASP.NET MVC action method name.
  • CONTROLLER - ASP.NET MVC controller class name.

See Also

Reference