Predefined Live Templates for C#
This topic lists all predefined live templates for C# in JetBrains Rider 2021.2. For more information about live templates, see Create source code using live templates
Template | Details |
---|---|
| 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.
// *********************************************************************** Parameters
|
| Test Method Scope C# 2.0+ type members Body [Test]
public void $TEST_METHOD$()
{
$END$
} Parameters
|
| Test Fixture Scope C# 2.0+ types and namespaces, C# 2.0+ type members Body [TestFixture]
public class $TEST_CLASS$
{
[Test]
public void $TEST_METHOD$()
{
$END$
}
} Parameters
|
| Scope C# 2.0+ Body public $AAA$ One()
{
var x = new $AAA$();
return null;
}
public $AAA$ Two()
{
var x = new $AAA$();
var y = new $AAA$();
var z = new $AAA$();
return null;
} Parameters
|
| Current file context Scope everywhere Body $CTX$ Parameters
This could be useful:
Before expansion Expansion options |
| Insert new GUID Scope everywhere Body $GUID$ Parameters
|
| Join clause in language integrated query Scope C# 2.0+ queries Body join $NAME$ in $COL$ on $EXPR1$ equals $EXPR2$ $END$ Parameters
Before expansion After expansion |
| Language-Integrated Query Scope C# 3.0+ expressions, C# 3.0+ queries Body from $VAR$ in $COLLECTION$ $END$ Parameters
Before expansion After expansion |
| foreach block Scope C# 2.0+ statements Body foreach ($TYPE$ $VARIABLE$ in $COLLECTION$)
{
$SELECTION$$END$
} Parameters
Before expansion After expansion After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
| Iterate a IList<T> Scope C# 2.0+ statements Body for (int $INDEX$ = 0; $INDEX$ < $LIST$.Count; $INDEX$++)
{
$TYPE$ $ITEM$ = $LIST$[$INDEX$];
$END$
} Parameters
Before expansion After expansion The template generates a After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
| Iterate an array Scope C# 2.0+ statements Body for (int $INDEX$ = 0; $INDEX$ < $ARRAY$.Length; $INDEX$++)
{
$TYPE$ $VAR$ = $ARRAY$[$INDEX$];
$END$
} Parameters
Before expansion After expansion After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
| 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
Before expansion After expansion The template generates a After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
| Simple "for" loop Scope C# 2.0+ statements Body for (int $INDEX$ = 0; $INDEX$ < $UPPER$; $INDEX$++)
{
$SELECTION$$END$
} Parameters
Before expansion After expansion After you specify the parameters, the caret is positioned so that you can continue coding the loop body. |
| Safely cast variable Scope C# 2.0+ statements Body $VARTYPE$ $VAR$ = $VAR1$ as $TYPE$;
if ($VAR$ != null)
{
$END$
} Parameters
Before expansion After expansion |
| The "Main" method declaration Scope C# 2.0+ type members Body public static void Main( string[] args )
{
$END$
} Parameters
Before expansion After expansion |
| Print value of a variable Scope C# 2.0+ statements Body System.Console.Out.WriteLine("$EXPR$ = {0}", $EXPR$); Parameters
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 ( |
| Print a string Scope C# 2.0+ statements Body System.Console.Out.WriteLine("$END$"); Parameters
Before expansion After expansion |
| Make an assertion Scope C# 2.0+ statements Body System.Diagnostics.Debug.Assert($END$); Parameters
Before expansion After expansion This template calls the |
| Assert expression not null Scope C# 2.0+ statements Body System.Diagnostics.Debug.Assert($EXPR$ != null, "$MESSAGE$"); Parameters
Before expansion After expansion The template inserts the |
| throw new Scope C# 2.0+ statements Body throw new Before expansion After expansion |
| public const int Scope C# 2.0+ type members Body public const int Before expansion After expansion |
| public const string Scope C# 2.0+ type members Body public const string Before expansion After expansion |
| public static readonly Scope C# 2.0+ type members Body public static readonly Before expansion After expansion |
| Property Scope C# 2.0+ type members Body public $TYPE$ $NAME$ { get; set; } Parameters
Before expansion After expansion |
| Create an empty array Scope C# 2.0+ statements Body $TYPE$[] $NAME$ = new $TYPE$[] {}; Parameters
Before expansion After expansion |
| Scope C# 2.0+ except strings, at line start Body #if $expression$
$SELECTION$$END$
#endif Parameters
|
| Scope C# 2.0+ except strings, at line start Body #region $name$
$SELECTION$$END$
#endregion Parameters
|
| Scope C# 2.0+ type members, C# 2.0+ types and namespaces Body enum $name$
{
$END$
} Parameters
|
| else statement Scope C# 2.0+ statements Body else
{
$END$
} Parameters
|
| Destructor Scope C# 2.0+ type members Body ~$classname$()
{
$END$
} Parameters
|
| Constructor Scope C# 2.0+ type members Body public $classname$ ()
{
$END$
} Parameters
|
| Console.WriteLine Scope C# 2.0+ statements Body System.Console.WriteLine($END$); Parameters
|
| Scope C# 2.0+ type members, C# 2.0+ types and namespaces Body class $name$
{
$END$
} Parameters
|
| 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
|
| Scope C# 2.0+ type members, C# 2.0+ types and namespaces Body struct $name$
{
$END$
} Parameters
|
| Reverse 'for' loop Scope C# 2.0+ statements Body for (int $index$ = $max$ - 1; $index$ >= 0 ; $index$--)
{
$END$
} Parameters
|
| Scope C# 2.0+ types and namespaces Body namespace $name$
{
$END$$SELECTION$
} Parameters
|
| Scope C# 2.0+ type members, C# 2.0+ types and namespaces Body interface I$name$
{
$END$
} Parameters
|
| 'int Main' method Scope C# 2.0+ type members Body static int Main(string[] args)
{
$END$
return 0;
} Parameters
|
| 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
|
| 'void Main' method Scope C# 2.0+ type members Body static void Main(string[] args)
{
$END$
} Parameters
|
| unsafe statement Scope C# 2.0+ statements Body unsafe
{
$END$
} Parameters
|
| unchecked block Scope C# 2.0+ statements Body unchecked
{
$END$
} Parameters
|
| try finally Scope C# 2.0+ statements Body try
{
$SELECTION$
}
finally
{
$END$
} Parameters
|
| try catch Scope C# 2.0+ statements Body try
{
$SELECTION$
}
catch ($EXCEPTION$ $EX_NAME$)
{
$SELSTART$System.Console.WriteLine($EX_NAME$);
throw;$SELEND$
} Parameters
|
| switch statement Scope C# 2.0+ statements Body switch ($expression$)
{
$END$
} Parameters
|
| while loop Scope C# 2.0+ statements Body while ($expression$)
{
$SELECTION$$END$
} Parameters
|
| simple iterator Scope C# 2.0+ type members Body public $SystemCollectionsGenericIEnumeratorG$<$type$> GetEnumerator()
{
$SELSTART$throw new System.NotImplementedException();
yield return default($type$);
$SELEND$
} Parameters
|
| Property with a 'get' accessor and a private 'set' accessor Scope C# 2.0+ type members Body public $type$ $property$ { get; private set; } Parameters
|
| 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
|
| do...while loop Scope C# 2.0+ statements Body do
{
$SELECTION$$END$
} while ($expression$); Parameters
|
| checked block Scope C# 2.0+ statements Body checked
{
$END$
} Parameters
|
| if statement Scope C# 2.0+ statements Body if ($expr$)
{
$SELECTION$$END$
} Parameters
|
| lock statement Scope C# 2.0+ statements Body lock ($expression$)
{
$SELECTION$$END$
} Parameters
|
| MessageBox.Show Scope C# 2.0+ statements Body System.Windows.Forms.MessageBox.Show("$string$"); Parameters
|
| using statement Scope C# 2.0+ statements Body using($resource$)
{
$SELECTION$$END$
} Parameters
|
| ASP.NET MVC Html.ActionLink Scope C# 2.0+ expressions Body Html.ActionLink("$TEXT$", "$ACTION$", "$CONTROLLER$") Parameters
Before expansion After expansion |
| ASP.NET MVC Url.Action Scope C# 2.0+ expressions Body Url.Action("$ACTION$", "$CONTROLLER$") Parameters
Before expansion After expansion |
| ASP.NET Controller RedirectToAction Scope C# 2.0+ expressions Body RedirectToAction("$ACTION$", "$CONTROLLER$") Parameters
Before expansion After expansion |
| 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
The template creates an attached property with required get and set procedures. |
| 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
|