Visual Studio like code snippets in Rider
Asked Answered
A

1

26

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
}
Apteral answered 28/8, 2017 at 12:23 Comment(0)
R
43

Yes, there is.

In Rider, it is called Live Templates.

  • Open menu File > Settings.
  • In the Settings window, expand Editor > Live Templates.
  • Then select the language you want. Let's say C#.
  • The settings window shows the list of shortcuts.
  • Click the New Template icon on the right.Settings
  • In the Shortcut field, define the keyword you want to use to trigger it.
  • You can select any other shortcut to have an example.
  • Save your changes.
  • Go to the editor and type the "shortcut".
  • 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.

Rainarainah answered 6/9, 2017 at 4:46 Comment(2)
Referencing youtrack.jetbrains.com/oauth?state=%2Fissue%2FRIDER-548 for pending feature of creating C# Live Templates in RiderCharente
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?Ahmad

© 2022 - 2024 — McMap. All rights reserved.