Predefined Live Templates for C#
This topic lists all predefined live templates for C# in ReSharper 2016.3.1. For more information about live templates, see Creating Source Code Using Live Templates
Template | Details |
---|---|
ctx | Current file context $CTX$
This could be useful:
|
join | Join clause in language integrated query join $NAME$ in $COL$ on $EXPR1$ equals $EXPR2$ $END$
|
from | Language-Integrated Query Scope C# 3.0+ expressions, C# 3.0+ queries from $VAR$ in $COLLECTION$ $END$
|
foreach | foreach block foreach ($TYPE$ $VARIABLE$ in $COLLECTION$)
{
$SELECTION$$END$
}
Before expansion After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
itli | Iterate a IList<T> for (int $INDEX$ = 0; $INDEX$ < $LIST$.Count; $INDEX$++)
{
$TYPE$ $ITEM$ = $LIST$[$INDEX$];
$END$
}
Before expansion The template generates a After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
itar | Iterate an array for (int $INDEX$ = 0; $INDEX$ < $ARRAY$.Length; $INDEX$++)
{
$TYPE$ $VAR$ = $ARRAY$[$INDEX$];
$END$
}
Before expansion 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 for (int $INDEX$ = $ARRAY$.Length - 1; $INDEX$ >= 0; $INDEX$--)
{
$TYPE$ $VAR$ = $ARRAY$[$INDEX$];
$END$
}
Before expansion The template generates a After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
for | Simple "for" loop for (int $INDEX$ = 0; $INDEX$ < $UPPER$; $INDEX$++)
{
$SELECTION$$END$
}
Before expansion After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
sfc | Safely cast variable $VARTYPE$ $VAR$ = $VAR1$ as $TYPE$;
if ($VAR$ != null)
{
$END$
}
|
psvm | The "Main" method declaration public static void Main( string[] args )
{
$END$
} |
outv | Print value of a variable System.Console.Out.WriteLine("$EXPR$ = {0}", $EXPR$);
Before 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 ( |
out | Print a string System.Console.Out.WriteLine("$END$"); |
asrt | Make an assertion System.Diagnostics.Debug.Assert($END$); Before expansion This template calls the |
asrtn | Assert expression not null System.Diagnostics.Debug.Assert($EXPR$ != null, "$MESSAGE$"); Before expansion The template inserts the |
thr | throw new throw new |
pci | public const int public const int |
pcs | public const string public const string |
psr | public static readonly public static readonly |
prop | Property public $TYPE$ $NAME$ { get; set; }
|
ear | Create an empty array $TYPE$[] $NAME$ = new $TYPE$[] {};
|
nguid | Insert new GUID $GUID$
|
#if (Imported Visual C# Snippets) | Code snippet for #if Scope C# 2.0+ except strings, C# 2.0+ #if $expression$
$SELECTION$$END$
#endif
|
#region (Imported Visual C# Snippets) | Code snippet for #region Scope C# 2.0+ except strings, C# 2.0+ #region $name$
$SELECTION$$END$
#endregion
|
enum (Imported Visual C# Snippets) | Code snippet for enum Scope C# 2.0+ type members, C# 2.0+ types and namespaces enum $name$
{
$END$
}
|
else (Imported Visual C# Snippets) | Code snippet for else statement else
{
$END$
} |
~ (Imported Visual C# Snippets) | Code snippet for destructor ~$classname$()
{
$END$
}
|
ctor (Imported Visual C# Snippets) | Code snippet for constructor public $classname$ ()
{
$END$
}
|
cw (Imported Visual C# Snippets) | Code snippet for Console.WriteLine System.Console.WriteLine($END$); |
class (Imported Visual C# Snippets) | Code snippet for class Scope C# 2.0+ type members, C# 2.0+ types and namespaces class $name$
{
$END$
}
|
Exception (Imported Visual C# Snippets) | Code snippet for exception Scope C# 2.0+ type members, C# 2.0+ types and namespaces [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 ) { }
}
|
struct (Imported Visual C# Snippets) | Code snippet for struct Scope C# 2.0+ type members, C# 2.0+ types and namespaces struct $name$
{
$END$
}
|
forr (Imported Visual C# Snippets) | Code snippet for reverse 'for' loop for (int $index$ = $max$ - 1; $index$ >= 0 ; $index$--)
{
$END$
} |
namespace (Imported Visual C# Snippets) | Code snippet for namespace Scope C# 2.0+ types and namespaces namespace $name$
{
$END$$SELECTION$
}
|
interface (Imported Visual C# Snippets) | Code snippet for interface Scope C# 2.0+ type members, C# 2.0+ types and namespaces interface I$name$
{
$END$
}
|
sim (Imported Visual C# Snippets) | Code snippet for int Main() static int Main(string[] args)
{
$END$
return 0;
} |
indexer (Imported Visual C# Snippets) | Code snippet for indexer $access$ $type$ this[$indextype$ index]
{
get {$END$ /* return the specified index here */ }
set { /* set the specified index to value here */ }
} |
svm (Imported Visual C# Snippets) | Code snippet for 'void Main' method static void Main(string[] args)
{
$END$
} |
unsafe (Imported Visual C# Snippets) | Code snippet for unsafe statement unsafe
{
$END$
} |
unchecked (Imported Visual C# Snippets) | Code snippet for unchecked block unchecked
{
$END$
} |
tryf (Imported Visual C# Snippets) | Code snippet for try finally try
{
$SELECTION$
}
finally
{
$END$
} |
try (Imported Visual C# Snippets) | Code snippet for try catch try
{
$SELECTION$
}
catch ($EXCEPTION$ $EX_NAME$)
{
$SELSTART$System.Console.WriteLine($EX_NAME$);$SELEND$
throw;
}
|
switch (Imported Visual C# Snippets) | Code snippet for switch statement switch ($expression$)
{
$END$
}
|
while (Imported Visual C# Snippets) | Code snippet for while loop while ($expression$)
{
$SELECTION$$END$
}
|
iterator (Imported Visual C# Snippets) | Code snippet for a simple iterator public $SystemCollectionsGenericIEnumeratorG$<$type$> GetEnumerator()
{
$SELSTART$throw new System.NotImplementedException();
yield return default($type$);
$SELEND$
} |
propg (Imported Visual C# Snippets) | Code snippet for an automatically implemented property with a 'get' accessor and a private 'set' accessor public $type$ $property$ { get; private set; }
|
Attribute (Imported Visual C# Snippets) | Code snippet for attribute using recommended pattern Scope C# 2.0+ type members, C# 2.0+ types and namespaces [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; }
} |
do (Imported Visual C# Snippets) | Code snippet for do...while loop do
{
$SELECTION$$END$
} while ($expression$);
|
checked (Imported Visual C# Snippets) | Code snippet for checked block checked
{
$END$
} |
if (Imported Visual C# Snippets) | Code snippet for if statement if ($expression$)
{
$SELECTION$$END$
}
|
lock (Imported Visual C# Snippets) | Code snippet for lock statement lock ($expression$)
{
$SELECTION$$END$
}
|
mbox (Imported Visual C# Snippets) | Code snippet for MessageBox.Show System.Windows.Forms.MessageBox.Show("$string$");
|
using (Imported Visual C# Snippets) | Code snippet for using statement using($resource$)
{
$SELECTION$$END$
}
|
hal | ASP.NET MVC Html.ActionLink Html.ActionLink("$TEXT$", "$ACTION$", "$CONTROLLER$")
|
ua | ASP.NET MVC Url.Action Url.Action("$ACTION$", "$CONTROLLER$")
|
rta | ASP.NET Controller RedirectToAction RedirectToAction("$ACTION$", "$CONTROLLER$")
|
attachedProperty | Attached property 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);
}
The template creates an attached property with required get and set procedures. |
dependencyProperty | Dependency property 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); }
}
|