23

Does anyone know if the JetBrains Rider IDE supports kind of "code snippets"? I usually have a snippet in Visual Studio for creating NUnit test cases, like:

[Test]
[Description("Some description")]
[MaxTime(1000)]
public void Test()
{
#region Arrange
#endregion

#region Assert
#endregion

#region Act
#endregion
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Moerwald
  • 10,448
  • 9
  • 43
  • 83

1 Answers1

39

Yes, there is.

In Rider, it is called Live Templates.

  • Open menu File > Settings.
  • In the Settings window, expand Editor > Live Templates.
  • Click the green "+" icon to add a Template Group.
  • Click the green "+" icon to add a Template.
  • In the Abbreviation field, define the keyword you want to use to trigger it.
  • In the field Template Text, insert the code.
  • In the field Applicable in, set the context where this live template will be used.
  • In the field Expand with, select how you want to expand the code after typing your keyword.
  • Save your changes.
  • Go to the editor and type the abbreviation, and then the key you defined in the Expand with field.
  • Rider will create the code for you.

Keep in mind that Live Templates use a different syntax from Visual Studio Code Snippets, so you can check this page - Predefined Live Templates for C# - for further reference.

Pang
  • 9,564
  • 146
  • 81
  • 122
Marlon Assef
  • 1,441
  • 15
  • 18
  • 1
    Referencing https://youtrack.jetbrains.com/oauth?state=%2Fissue%2FRIDER-548 for pending feature of creating C# Live Templates in Rider – Strake Mar 09 '18 at 20:14
  • Would it be possible for you to update this? Most of the terms from step 3 are different today. ie. Abbreviation now says shortcut. Also; There is no Expand With. In step 10 you mention a key - What is this key you refer to? – Christian Mar 17 '23 at 07:37