ReSharper 8.0 Web Help

ReSharper | Templates Explorer | Live 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

After expansion

Parameters

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

asrtn

Go to top

Purpose
This template inserts the Debug.Assert method, which/that checks a condition and displays a message if the condition is false.

System.Diagnostics.Debug.Assert($EXPR$ != null, "$MESSAGE$");

Before expansion

After expansion

Parameters

  • EXPR - condition to be checked
  • MESSAGE - message to be displayed if the condition is false

attachedProperty

Go to top

Purpose
This template creates an attached property with required get and set procedures.

public static readonly DependencyProperty $propertyName$Property =
  DependencyProperty.RegisterAttached("$propertyName$", typeof ($propertyType$), typeof ($containingType$), new PropertyMetadata(default($propertyType$)));

public static void Set$propertyName$($UIElement$ $element$, $propertyType$ value)
{
  $element$.SetValue($propertyName$Property, value);
}

public static $propertyType$ Get$propertyName$($UIElement$ $element$)
{
  return ($propertyType$) $element$.GetValue($propertyName$Property);
}

Before expansion

After expansion

Parameters

  • propertyName - name of attached property
  • propertyType - type of attached property
  • containingType - type that contains attached property
  • UIElement - type of object with attached property
  • element - object that has specified attached property

dependencyProperty

Go to top

Purpose
This template inserts dependency property with necessary wrapper.

public static readonly System.Windows.DependencyProperty $propertyName$Property =
  System.Windows.DependencyProperty.Register("$propertyName$", typeof ($propertyType$), typeof ($containingType$), new PropertyMetadata(default($propertyType$)));

public $propertyType$ $propertyName$
{
  get { return ($propertyType$) GetValue($propertyName$Property); }
  set { SetValue($propertyName$Property, value); }
}

Before expansion

After expansion

Parameters

  • propertyName - name of dependency property
  • propertyType - type of dependency property
  • containingType - type that contains dependency property

ear

Go to top

Purpose
Generates a code fragment that creates an empty array.

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

Before expansion

After expansion

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

After expansion

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

After expansion

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

After expansion

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

After expansion

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

After expansion

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

After expansion

pcs

Go to top

Purpose
Declares a constant string.

public const string

Before expansion

After expansion

prop

Go to top

Purpose
Generates an auto-property.

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

Before expansion

After expansion

Parameters

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

psr

Go to top

Purpose
Generates a static read-only field.

public static readonly

Before expansion

After expansion

psvm

Go to top

Purpose
Generates the Main() application method.

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

Before expansion

After expansion

Parameters

  • END - method body.

rta

Go to top

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

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

Before expansion

After expansion

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

After expansion

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

After expansion

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

After expansion

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

After expansion

Parameters

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

See Also

Reference