ReSharper 10.0 Help

Predefined Live Templates for C#

ReSharper | Tools | Templates Explorer | Live Templates | C#

This topic lists all predefined live templates for C# in ReSharper 10 EAP 3. For more information about live templates, see Creating Source Code Using Live Templates

TemplateDetails
join

Join clause in language integrated query

Scope C# 2.0+ queries

Body

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

Parameters

  • COL - Suggests variables of the specified type. (variableOfType)
  • NAME - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • EXPR1 - no macro
  • EXPR2 - no macro
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__join__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__join__after

from

Language-Integrated Query

Scope C# 3.0+ expressions, C# 3.0+ queries

Body

from $VAR$ in $COLLECTION$ $END$

Parameters

  • COLLECTION - Suggests variables of the specified type. (variableOfType)
  • VAR - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__from__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__from__after

foreach

foreach block

Scope C# 2.0+ statements

Body

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

Parameters

  • COLLECTION - Show basic code completion list at the point where the variable is evaluated (complete)
  • TYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • VARIABLE - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__foreach__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__foreach__after

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

itdic

Iterate a Dictionary

Scope C# 2.0+ statements

Body

foreach (System.Collections.DictionaryEntry $ENTRY$ in $DICT$) { $KEYTYPE$ $KEY$ = $CASTKEY$$ENTRY$.Key; $VALTYPE$ $VAL$ = $CASTVALUE$$ENTRY$.Value; $END$ }

Parameters

  • DICT - Suggests variables of the specified type. (variableOfType)
  • ENTRY - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • KEYTYPE - Analyzes code and guesses type of key of a dictionary collection. (guessKeyType)
  • KEY - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • CASTKEY - Inserts (if required) cast to the type which is expected at the left side of assignment expression. (castToLeftSideType)
  • VALTYPE - Analyzes code and guesses type of value of a dictionary collection. (guessValueType)
  • VAL - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • CASTVALUE - Inserts (if required) cast to the type which is expected at the left side of assignment expression. (castToLeftSideType)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itdic__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itdic__after

The template generates a foreach block which iterates over a System.Collections.IDictionary collection. Unlike itdg, it provides fully-qualified type name for iterator variable in the loop condition and performs type casts over the key and the value of a dictionary element in the loop body. Includes two customizable statements in the loop body with two variables holding the key and the value of a dictionary element.

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

itdg

Iterate a Dictionary<K, V>

Scope C# 2.0+ statements

Body

foreach ($DETYPE$ $ENTRY$ in $DICT$) { $KEYTYPE$ $KEY$ = $ENTRY$.Key; $VALTYPE$ $VAL$ = $ENTRY$.Value; $END$ }

Parameters

  • DICT - Suggests variables of the specified type. (variableOfType)
  • ENTRY - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • DETYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • KEYTYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • KEY - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • VALTYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • VAL - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itdg__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itdg__after

The template generates a foreach block which iterates over a System.Collections.Generic.IDictionary collection. Includes two customizable statements in the loop body with two variables holding the key and the value of a dictionary element.

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

itli

Iterate a IList<T>

Scope C# 2.0+ statements

Body

for (int $INDEX$ = 0; $INDEX$ < $LIST$.Count; $INDEX$++) { $TYPE$ $ITEM$ = $LIST$[$INDEX$]; $END$ }

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point. (suggestIndexVariable)
  • LIST - Suggests variables of the specified type. (variableOfType)
  • TYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • ITEM - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itli__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itli__after

The template generates a for loop which iterates over an instance of System.Collections.IList. Includes a customizable statement in the loop body with a variable holding container elements.

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

itar

Iterate an array

Scope C# 2.0+ statements

Body

for (int $INDEX$ = 0; $INDEX$ < $ARRAY$.Length; $INDEX$++) { $TYPE$ $VAR$ = $ARRAY$[$INDEX$]; $END$ }

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point. (suggestIndexVariable)
  • ARRAY - Suggests variable which type is array type (arrayVariable)
  • TYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • VAR - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itar__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__itar__after

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

ital

Iterate an ArrayList

Scope C# 2.0+ statements

Body

for (int $INDEX$ = 0; $INDEX$ < $ARRAY$.Count; $INDEX$++) { $TYPE$ $VAR$ = ($TYPE$)$ARRAY$[$INDEX$]; $END$ }

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point. (suggestIndexVariable)
  • ARRAY - Suggests variables of the specified type. (variableOfType)
  • TYPE - Analyzes code and guesses type of element of a collection. (guessElementType)
  • VAR - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__ital__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__ital__after

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

ritar

Iterate an array in inverse order

Scope C# 2.0+ statements

Body

for (int $INDEX$ = $ARRAY$.Length - 1; $INDEX$ >= 0; $INDEX$--) { $TYPE$ $VAR$ = $ARRAY$[$INDEX$]; $END$ }

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point. (suggestIndexVariable)
  • ARRAY - Suggests variable which type is array type (arrayVariable)
  • TYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • VAR - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__ritar__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__ritar__after

The template generates a for loop for iterating over an array in reverse order. Includes a customizable statement in the loop body with a variable holding container elements.

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

for

Simple "for" loop

Scope C# 2.0+ statements

Body

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

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point. (suggestIndexVariable)
  • UPPER - no macro
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__loop__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Iteration__loop__after

After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

toar

Convert an ArrayList to array

Scope C# 2.0+ expressions

Body

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

Parameters

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__toar__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__toar__after

The template generates a code fragment that copies the elements of System.Collections.ArrayList to an array using the ToArray() method. It is most efficiently used where the required element type can be determined from the context.

sfc

Safely cast variable

Scope C# 2.0+ statements

Body

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

Parameters

  • VAR1 - Suggests variables of the specified type. (variableOfType)
  • TYPE - no macro
  • VARTYPE - Suggest type for a new variable declared in the template (suggestVariableType)
  • VAR - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • END - The caret position after the template is applied.

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__sfc__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__sfc__after

psvm

The "Main" method declaration

Scope C# 2.0+ type members

Body

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

Parameters

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

Before expansion

Invoking the 'public static void Main' template with %product%'s code completion

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__psvm__after

outv

Print value of a variable

Scope C# 2.0+ statements

Body

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

Parameters

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__outv__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__outv__after

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.

out

Print a string

Scope C# 2.0+ statements

Body

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

Parameters

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

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__out__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__out__after

asrt

Make an assertion

Scope C# 2.0+ statements

Body

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

Parameters

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

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__asrt__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__asrt__after

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.

asrtn

Assert expression not null

Scope C# 2.0+ statements

Body

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

Parameters

  • EXPR - no macro
  • MESSAGE - no macro

Before expansion

Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__asrtn__before

After expansion
Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__asrtn__after

The template inserts the Debug.Assert method, which checks a condition and displays a message if the condition is false.

thr

throw new

Scope C# 2.0+ statements

Body

throw new

    Before expansion

    Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__thr__before

    After expansion
    Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__thr__after

    pci

    public const int

    Scope C# 2.0+ type members

    Body

    public const int

      Before expansion

      Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__pci__before

      After expansion
      Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__pci__after

      pcs

      public const string

      Scope C# 2.0+ type members

      Body

      public const string

        Before expansion

        Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__pcs__before

        After expansion
        Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__pcs__after

        psr

        public static readonly

        Scope C# 2.0+ type members

        Body

        public static readonly

          Before expansion

          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__psr__before

          After expansion
          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__psr__after

          prop

          Property

          Scope C# 2.0+ type members

          Body

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

          Parameters

          • TYPE - no macro
          • NAME - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)

          Before expansion

          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__prop__before

          After expansion
          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__prop__after

          ear

          Create an empty array

          Scope C# 2.0+ statements

          Body

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

          Parameters

          • TYPE - no macro
          • NAME - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)

          Before expansion

          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ear__before

          After expansion
          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ear__after

          #if (Imported Visual C# Snippets)

          Code snippet for #if

          Scope C# 2.0+

          Body

          #if $expression$ $END$ #endif

          Parameters

          • expression - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          #region (Imported Visual C# Snippets)

          Code snippet for #region

          Scope C# 2.0+

          Body

          #region $name$ $END$ #endregion

          Parameters

          • name - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          enum (Imported Visual C# Snippets)

          Code snippet for enum

          Scope C# 2.0+ type members, C# 2.0+ types and namespaces

          Body

          enum $name$ { $END$ }

          Parameters

          • name - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          else (Imported Visual C# Snippets)

          Code snippet for else statement

          Scope C# 2.0+ statements

          Body

          else { $END$ }

          Parameters

          • END - The caret position after the template is applied.
          ~ (Imported Visual C# Snippets)

          Code snippet for destructor

          Scope C# 2.0+ type members

          Body

          ~$classname$() { $END$ }

          Parameters

          • classname - Evaluates to short name of the most inner containing type. (typeName)
          • END - The caret position after the template is applied.
          ctor (Imported Visual C# Snippets)

          Code snippet for constructor

          Scope C# 2.0+ type members

          Body

          public $classname$ () { $END$ }

          Parameters

          • classname - Evaluates to short name of the most inner containing type. (typeName)
          • END - The caret position after the template is applied.
          cw (Imported Visual C# Snippets)

          Code snippet for Console.WriteLine

          Scope C# 2.0+ statements

          Body

          System.Console.WriteLine($END$);

          Parameters

          • END - The caret position after the template is applied.
          class (Imported Visual C# Snippets)

          Code snippet for class

          Scope C# 2.0+ type members, C# 2.0+ types and namespaces

          Body

          class $name$ { $END$ }

          Parameters

          • name - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          Exception (Imported Visual C# Snippets)

          Code snippet for exception

          Scope C# 2.0+ type members, C# 2.0+ types and namespaces

          Body

          [System.Serializable] public class $newException$Exception : System.Exception { // // For guidelines regarding the creation of new exception types, see // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp // and // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp // public $newException$Exception() { } public $newException$Exception( string message ) : base( message ) { } public $newException$Exception( string message, System.Exception inner ) : base( message, inner ) { } protected $newException$Exception( System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context ) : base( info, context ) { } }

          Parameters

          • newException - Evaluates to the specified constant value. (constant)
          equals (Imported Visual C# Snippets)

          Code snippet for implementing Equals() according to guidelines

          Scope C# 2.0+ type members

          Body

          // override object.Equals public override bool Equals (object obj) { // // See the full list of guidelines at // http://go.microsoft.com/fwlink/?LinkID=85237 // and also the guidance for operator== at // http://go.microsoft.com/fwlink/?LinkId=85238 // if (obj == null || GetType() != obj.GetType()) { return false; } // TODO: write your implementation of Equals() here throw new System.NotImplementedException(); return base.Equals (obj);$END$ } // override object.GetHashCode public override int GetHashCode() { // TODO: write your implementation of GetHashCode() here throw new System.NotImplementedException(); return base.GetHashCode(); }

          Parameters

          • END - The caret position after the template is applied.
          struct (Imported Visual C# Snippets)

          Code snippet for struct

          Scope C# 2.0+ type members, C# 2.0+ types and namespaces

          Body

          struct $name$ { $END$ }

          Parameters

          • name - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          invoke (Imported Visual C# Snippets)

          Code snippet for safely invoking an event

          Scope C# 2.0+ statements

          Body

          $DelegateType$ temp = $event$; if (temp != null) { temp($END$); }

          Parameters

          • event - Evaluates to the specified constant value. (constant)
          • DelegateType - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          forr (Imported Visual C# Snippets)

          Code snippet for reverse 'for' loop

          Scope C# 2.0+ statements

          Body

          for (int $index$ = $max$ - 1; $index$ >= 0 ; $index$--) { $END$ }

          Parameters

          • index - Evaluates to the specified constant value. (constant)
          • max - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          namespace (Imported Visual C# Snippets)

          Code snippet for namespace

          Scope C# 2.0+ types and namespaces

          Body

          namespace $name$ { $END$ }

          Parameters

          • name - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          interface (Imported Visual C# Snippets)

          Code snippet for interface

          Scope C# 2.0+ type members, C# 2.0+ types and namespaces

          Body

          interface I$name$ { $END$ }

          Parameters

          • name - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          sim (Imported Visual C# Snippets)

          Code snippet for int Main()

          Scope C# 2.0+ type members

          Body

          static int Main(string[] args) { $END$ return 0; }

          Parameters

          • END - The caret position after the template is applied.
          indexer (Imported Visual C# Snippets)

          Code snippet for indexer

          Scope C# 2.0+ type members

          Body

          $access$ $type$ this[$indextype$ index] { get {$END$ /* return the specified index here */ } set { /* set the specified index to value here */ } }

          Parameters

          • access - Evaluates to the specified constant value. (constant)
          • type - Evaluates to the specified constant value. (constant)
          • indextype - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          svm (Imported Visual C# Snippets)

          Code snippet for 'void Main' method

          Scope C# 2.0+ type members

          Body

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

          Parameters

          • END - The caret position after the template is applied.
          unsafe (Imported Visual C# Snippets)

          Code snippet for unsafe statement

          Scope C# 2.0+ statements

          Body

          unsafe { $END$ }

          Parameters

          • END - The caret position after the template is applied.
          unchecked (Imported Visual C# Snippets)

          Code snippet for unchecked block

          Scope C# 2.0+ statements

          Body

          unchecked { $END$ }

          Parameters

          • END - The caret position after the template is applied.
          tryf (Imported Visual C# Snippets)

          Code snippet for try finally

          Scope C# 2.0+ statements

          Body

          try { } finally { $END$ }

          Parameters

          • END - The caret position after the template is applied.
          try (Imported Visual C# Snippets)

          Code snippet for try catch

          Scope C# 2.0+ statements

          Body

          try { } catch (System.Exception) { $END$ throw; }

          Parameters

          • END - The caret position after the template is applied.
          switch (Imported Visual C# Snippets)

          Code snippet for switch statement

          Scope C# 2.0+ statements

          Body

          switch ($expression$) { $END$ }

          Parameters

          • expression - Suggests variables of the specified type. (variableOfType)
          • END - The caret position after the template is applied.
          while (Imported Visual C# Snippets)

          Code snippet for while loop

          Scope C# 2.0+ statements

          Body

          while ($expression$) { $END$ }

          Parameters

          • expression - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          iterator (Imported Visual C# Snippets)

          Code snippet for a simple iterator

          Scope C# 2.0+ type members

          Body

          public $SystemCollectionsGenericIEnumeratorG$<$type$> GetEnumerator() { $SELSTART$throw new System.NotImplementedException(); yield return default($type$); $SELEND$ }

          Parameters

          • type - Evaluates to the specified constant value. (constant)
          • SystemCollectionsGenericIEnumeratorG - Evaluates to the specified constant value. (constant)
          propg (Imported Visual C# Snippets)

          Code snippet for an automatically implemented property with a 'get' accessor and a private 'set' accessor

          Scope C# 2.0+ type members

          Body

          public $type$ $property$ { get; private set; }

          Parameters

          • type - Evaluates to the specified constant value. (constant)
          • property - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
          Attribute (Imported Visual C# Snippets)

          Code snippet for attribute using recommended pattern

          Scope C# 2.0+ type members, C# 2.0+ types and namespaces

          Body

          [System.AttributeUsage(System.AttributeTargets.$target$, Inherited = $inherited$, AllowMultiple = $allowmultiple$)] sealed class $name$Attribute : System.Attribute { // See the attribute guidelines at // http://go.microsoft.com/fwlink/?LinkId=85236 readonly string positionalString; // This is a positional argument public $name$Attribute (string positionalString) { this.positionalString = positionalString; // TODO: Implement code here $SELSTART$throw new System.NotImplementedException();$SELEND$ } public string PositionalString { get; private set; } // This is a named argument public int NamedInt { get; set; } }

          Parameters

          • name - Evaluates to the specified constant value. (constant)
          • target - Evaluates to the specified constant value. (constant)
          • inherited - Evaluates to the specified constant value. (constant)
          • allowmultiple - Evaluates to the specified constant value. (constant)
          do (Imported Visual C# Snippets)

          Code snippet for do...while loop

          Scope C# 2.0+ statements

          Body

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

          Parameters

          • expression - Suggests variables of the specified type. (variableOfType)
          • END - The caret position after the template is applied.
          checked (Imported Visual C# Snippets)

          Code snippet for checked block

          Scope C# 2.0+ statements

          Body

          checked { $END$ }

          Parameters

          • END - The caret position after the template is applied.
          if (Imported Visual C# Snippets)

          Code snippet for if statement

          Scope C# 2.0+ statements

          Body

          if ($expression$) { $END$ }

          Parameters

          • expression - Suggests variables of the specified type. (variableOfType)
          • END - The caret position after the template is applied.
          lock (Imported Visual C# Snippets)

          Code snippet for lock statement

          Scope C# 2.0+ statements

          Body

          lock ($expression$) { $END$ }

          Parameters

          • expression - Suggests variables of the specified type. (variableOfType)
          • END - The caret position after the template is applied.
          mbox (Imported Visual C# Snippets)

          Code snippet for MessageBox.Show

          Scope C# 2.0+ statements

          Body

          System.Windows.Forms.MessageBox.Show("$string$");

          Parameters

          • string - Evaluates to the specified constant value. (constant)
          iterindex (Imported Visual C# Snippets)

          Code snippet for 'named' iterator/indexer pair using a nested class

          Scope C# 2.0+ type members, C# 2.0+ types and namespaces

          Body

          public $name$Iterator $name$ { get { return new $name$Iterator(this); } } public class $name$Iterator { readonly $outer$ outer; internal $name$Iterator($outer$ outer) { this.outer = outer; } // TODO: provide an appropriate implementation here public int Length { get { return 1; } } public $type$ this[int index] { get { // // TODO: implement indexer here // // you have full access to $outer$ privates // $END$throw new System.NotImplementedException(); return default($type$); } } public $SystemCollectionsGenericIEnumeratorG$<$type$> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } }

          Parameters

          • type - Evaluates to the specified constant value. (constant)
          • name - Evaluates to the specified constant value. (constant)
          • outer - Evaluates to short name of the most inner containing type. (typeName)
          • SystemCollectionsGenericIEnumeratorG - Evaluates to the specified constant value. (constant)
          • END - The caret position after the template is applied.
          using (Imported Visual C# Snippets)

          Code snippet for using statement

          Scope C# 2.0+ statements

          Body

          using($resource$) { $END$ }

          Parameters

          • resource - Suggests variables of the specified type. (variableOfType)
          • END - The caret position after the template is applied.
          hal

          ASP.NET MVC Html.ActionLink

          Scope C# 2.0+ expressions

          Body

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

          Parameters

          • CONTROLLER - Show completion list with available ASP.NET MVC Controllers at the point where the variable is evaluated (AspMvcController)
          • ACTION - Show completion list with available ASP.NET MVC Actions at the point where the variable is evaluated (AspMvcAction)
          • TEXT - no macro

          Before expansion

          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__hal__before

          After expansion
          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__hal__after

          ua

          ASP.NET MVC Url.Action

          Scope C# 2.0+ expressions

          Body

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

          Parameters

          • CONTROLLER - Show completion list with available ASP.NET MVC Controllers at the point where the variable is evaluated (AspMvcController)
          • ACTION - Show completion list with available ASP.NET MVC Actions at the point where the variable is evaluated (AspMvcAction)

          Before expansion

          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ua__before

          After expansion
          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__ua__after

          rta

          ASP.NET Controller RedirectToAction

          Scope C# 2.0+ expressions

          Body

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

          Parameters

          • CONTROLLER - Show completion list with available ASP.NET MVC Controllers at the point where the variable is evaluated (AspMvcController)
          • ACTION - Show completion list with available ASP.NET MVC Actions at the point where the variable is evaluated (AspMvcAction)

          Before expansion

          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__rta__before

          After expansion
          Reference__Options__Templates__Live_Templates__Predefined__CSharp__Other__rta__after

          attachedProperty

          Attached property

          Scope C# 2.0+ type members

          Body

          public static readonly $dependencyProperty$ $propertyName$Property = $dependencyProperty$.RegisterAttached( "$propertyName$", typeof($propertyType$), typeof($containingType$), new PropertyMetadata(default($propertyType$))); public static void Set$propertyName$(DependencyObject $element$, $propertyType$ value) { $element$.SetValue($propertyName$Property, value); } public static $propertyType$ Get$propertyName$(DependencyObject $element$) { return ($propertyType$) $element$.GetValue($propertyName$Property); }

          Parameters

          • propertyType - no macro
          • propertyName - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
          • containingType - Evaluates to short name of the most inner containing type. (typeName)
          • element - no macro
          • dependencyProperty - Evaluates to dependency property type specific to current framework (dependencyPropertyType)

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

          dependencyProperty

          Dependency property

          Scope C# 2.0+ type members

          Body

          public static readonly $dependencyProperty$ $propertyName$Property = $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); } }

          Parameters

          • propertyType - no macro
          • propertyName - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
          • containingType - Evaluates to short name of the most inner containing type. (typeName)
          • dependencyProperty - Evaluates to dependency property type specific to current framework (dependencyPropertyType)
          ctx

          Current file context

          Scope everywhere

          Body

          $CTX$

          Parameters

          • CTX - Provides list of items describing current context. This includes file name, containing type name, namespace name, etc. (context)

          This could be useful:

          • In string literals that contain references to the current context, i.e. Logger.LogError("Cannot find action ActionNameDerivedFromContext");
          • As an alternative to code completion where IntelliSense doesn't work properly - for example, in comments when documenting a member with a long name (see example below).

          Before expansion

          Reference__Options__Templates__Live_Templates__Predefined__No_Language__ctx__before

          Expansion options
          Reference__Options__Templates__Live_Templates__Predefined__No_Language__ctx__expansion

          nguid

          Insert new GUID

          Scope everywhere

          Body

          $GUID$

          Parameters

          • GUID - Generates new Globally Unique Identifier (GUID) (guid)
          Last modified: 8 January 2016