ReSharper | Templates Explorer | Live Templates | C#
This topic lists all predefined live templates for C# in ReSharper 2024.3. For more information about live templates, refer to Create source code using live templates.
Template
Details
ctx
Current file context
Scope Everywhere
Body
$CTX$
Parameters
CTX - Provides a list of items describing current context. This includes file name, containing type name, namespace name, etc.
This template could be useful:
In string literals that contain references to the current context, that is Logger.LogError("Cannot find action ActionNameDerivedFromContext");
As an alternative to code completion where code completion doesn't work, for example, in comments when documenting a member with a long name.
Before expansion
Expansion options
nguid
Insert new GUID
Scope Everywhere
Body
$GUID$
Parameters
GUID - Generates a new Globally Unique Identifier (GUID)
join
Join clause in language integrated query
Scope C# 2.0+ queries
Body
join $NAME$ in $COL$ on $EXPR1$ equals $EXPR2$ $END$
Parameters
COL - Shows basic code completion list at the point where the variable is evaluated
NAME - When executed in a variable declaration (where variable name should stand), suggests a name for the variable
EXPR1 - no macro
EXPR2 - no macro
END - The caret position after the template is applied.
Before expansion
After expansion
from
Language-Integrated Query
Scope C# 3.0+ expressions, C# 3.0+ queries
Body
from $VAR$ in $COLLECTION$ $END$
Parameters
COLLECTION - Shows basic code completion list at the point where the variable is evaluated
VAR - When executed in a variable declaration (where variable name should stand), suggests a name for the variable
END - The caret position after the template is applied.
Before expansion
After expansion
foreach
foreach block
Scope C# 2.0+ statements
Body
foreach($TYPE$ $VARIABLE$ in $COLLECTION$){
$SELECTION$$END$
}
Parameters
COLLECTION - Shows basic code completion list at the point where the variable is evaluated
TYPE - Suggests a type for a new variable declared in the template
VARIABLE - When executed in a variable declaration (where variable name should stand), suggests a name for the variable
SELECTION - The text selected by the user before invoking the template.
END - The caret position after the template is applied.
Before expansion
After expansion
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.
INDEX - Suggests a unique name for an index variable at the evaluation point
LIST - Shows basic code completion list at the point where the variable is evaluated
TYPE - Suggests a type for a new variable declared in the template
ITEM - When executed in a variable declaration (where variable name should stand), suggests a name for the variable
END - The caret position after the template is applied.
Before expansion
After expansion
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.
INDEX - Suggests a unique name for an index variable at the evaluation point
ARRAY - Suggests a variable whose type is an array type
TYPE - Suggests a type for a new variable declared in the template
VAR - When executed in a variable declaration (where variable name should stand), suggests a name for the variable
END - The caret position after the template is applied.
Before expansion
After expansion
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.
EXPR - Shows basic code completion list at the point where the variable is evaluated
Before expansion
After expansion
ReSharper automatically suggests a list of all variables in the current scope and 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
After expansion
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
After expansion
This template calls the Debug.Assert method. After the template expanded, the caret moves between the parentheses so that you can specify a condition.
EXCEPTION - Evaluates to the specified constant value
EX_NAME - When executed in a variable declaration (where variable name should stand), suggests a name for the variable
SELECTION - The text selected by the user before invoking the template.
switch
switch statement
Scope C# 2.0+ statements
Body
switch($expression$){
$END$
}
Parameters
expression - Shows basic code completion list at the point where the variable is evaluated
END - The caret position after the template is applied.
while
while loop
Scope C# 2.0+ statements
Body
while($expression$){
$SELECTION$$END$
}
Parameters
expression - Shows 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.
iterator
simple iterator
Scope C# 2.0+ type members
Body
public $SystemCollectionsGenericIEnumeratorG$<$type$>GetEnumerator(){
$SELSTART$thrownewSystem.NotImplementedException();yieldreturndefault($type$);
$SELEND$
}
Parameters
type - Evaluates to the specified constant value
SystemCollectionsGenericIEnumeratorG - Evaluates to the specified constant value
propg
Property with a 'get' accessor and a private 'set' accessor
Scope C# 2.0+ type members
Body
public $type$ $property$ {get;privateset;}
Parameters
type - Evaluates to the specified constant value
property - When executed in a variable declaration (where variable name should stand), suggests a name for the variable
Attribute
Attribute using recommended pattern
Scope C# 2.0+ type members, C# 2.0+ types and namespaces