ReSharper | Templates Explorer | Live Templates | C#
This topic lists all predefined live templates for C# in ReSharper 2021.2. For more information about live templates, see Create source code using live templates
Template
Details
copyright
NUnit Copyright
Scope C# 2.0+ types and namespaces
Body
// ***********************************************************************// Copyright (c) $YEAR$ Charlie Poole//// Permission is hereby granted, free of charge, to any person obtaining// a copy of this software and associated documentation files (the// "Software"), to deal in the Software without restriction, including// without limitation the rights to use, copy, modify, merge, publish,// distribute, sublicense, and/or sell copies of the Software, and to// permit persons to whom the Software is furnished to do so, subject to// the following conditions://// The above copyright notice and this permission notice shall be// included in all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.// ***********************************************************************
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, 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 expansion
Expansion options
nguid
Insert new GUID
Scope everywhere
Body
$GUID$
Parameters
GUID- Generates new Globally Unique Identifier (GUID) (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. (variableOfType)
NAME- When executed 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
After 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. (variableOfType)
VAR- When executed 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
After 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 (complete)
TYPE- Suggest type for a new variable declared in the template (suggestVariableType)
VARIABLE- When executed in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
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 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 executed 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
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 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 executed 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
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- Suggests variables of the specified type. (variableOfType)
Before expansion
After expansion
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
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, 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. (constant)
EX_NAME- When executed in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
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- Suggests variables of the specified type. (variableOfType)
END- The caret position after the template is applied.
while
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 (complete)
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. (constant)
SystemCollectionsGenericIEnumeratorG- Evaluates to the specified constant value. (constant)
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. (constant)
property- When executed in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
Attribute
Attribute using recommended pattern
Scope C# 2.0+ type members, C# 2.0+ types and namespaces