This topic lists all predefined live templates for C# in JetBrains Rider 2019.3. For more information about live templates, see Create Source Code Using Live Templates
Template
Details
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.
This 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 IntelliSense doesn't work properly - for example, in comments when documenting a member with a long name (see example below).
Before expansionExpansion options
nguid
Insert new GUID
Scope everywhere
Body
$GUID$
Parameters
GUID - Generates 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 - Suggests variables of the specified type.
NAME - When executed in variable declaration (where variable name should stand), suggests name for the variable.
EXPR1 - no macro
EXPR2 - no macro
END - The caret position after the template is applied.
Before expansionAfter expansion
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.
VAR - When executed in variable declaration (where variable name should stand), suggests name for the variable.
END - The caret position after the template is applied.
Before expansionAfter expansion
foreach
foreach block
Scope C# 2.0+ statements
Body
foreach ($TYPE$ $VARIABLE$ in $COLLECTION$)
{
$SELECTION$$END$
}
Parameters
COLLECTION - Show basic code completion list at the point where the variable is evaluated
TYPE - Suggest type for a new variable declared in the template
VARIABLE - When executed in variable declaration (where variable name should stand), suggests 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 expansionAfter expansion
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.
INDEX - Suggests non-used name which can be used for an index variable at the evaluation point.
LIST - Suggests variables of the specified type.
TYPE - Suggest type for a new variable declared in the template
ITEM - When executed in variable declaration (where variable name should stand), suggests name for the variable.
END - The caret position after the template is applied.
Before expansionAfter 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 non-used name which can be used for an index variable at the evaluation point.
ARRAY - Suggests variable which type is array type
TYPE - Suggest type for a new variable declared in the template
VAR - When executed in variable declaration (where variable name should stand), suggests name for the variable.
END - The caret position after the template is applied.
Before expansionAfter 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.
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 expansionAfter 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 expansionAfter expansion
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.
EXCEPTION - Evaluates to the specified constant value.
EX_NAME - When executed in variable declaration (where variable name should stand), suggests name for the variable.
SELECTION - The text selected by the user before invoking the template.
switch (Imported Visual C# Snippets)
switch statement
Scope C# 2.0+ statements
Body
switch ($expression$)
{
$END$
}
Parameters
expression - Suggests variables of the specified type.
END - The caret position after the template is applied.
while (Imported Visual C# Snippets)
while loop
Scope C# 2.0+ statements
Body
while ($expression$)
{
$SELECTION$$END$
}
Parameters
expression - Show 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 (Imported Visual C# Snippets)
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.
SystemCollectionsGenericIEnumeratorG - Evaluates to the specified constant value.
propg (Imported Visual C# Snippets)
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.
property - When executed in variable declaration (where variable name should stand), suggests name for the variable.
Attribute (Imported Visual C# Snippets)
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
public $name$Attribute ()
{
$SELSTART$// TODO: Implement code here
throw new System.NotImplementedException();$SELEND$
}
}
Parameters
name - Evaluates to the specified constant value.
target - Evaluates to the specified constant value.
inherited - Evaluates to the specified constant value.
allowmultiple - Evaluates to the specified constant value.
do (Imported Visual C# Snippets)
do...while loop
Scope C# 2.0+ statements
Body
do
{
$SELECTION$$END$
} while ($expression$);
Parameters
expression - Suggests variables of the specified type.
SELECTION - The text selected by the user before invoking the template.
END - The caret position after the template is applied.
checked (Imported Visual C# Snippets)
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)
if statement
Scope C# 2.0+ statements
Body
if ($expr$)
{
$SELECTION$$END$
}
Parameters
expr - Show 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.
lock (Imported Visual C# Snippets)
lock statement
Scope C# 2.0+ statements
Body
lock ($expression$)
{
$SELECTION$$END$
}
Parameters
expression - Suggests variables of the specified type.
SELECTION - The text selected by the user before invoking the template.
END - The caret position after the template is applied.
mbox (Imported Visual C# Snippets)
MessageBox.Show
Scope C# 2.0+ statements
Body
System.Windows.Forms.MessageBox.Show("$string$");
Parameters
string - Evaluates to the specified constant value.
using (Imported Visual C# Snippets)
using statement
Scope C# 2.0+ statements
Body
using($resource$)
{
$SELECTION$$END$
}
Parameters
resource - Show 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.