Home > Code Generation, Coding Helpers, Options/Settings, Selection > Creating custom CodeRush Code Embeddings

Creating custom CodeRush Code Embeddings

September 12th, 2011

CodeRush Code Embeddings are completely customizable. They are modified on the Embeddings options page in the Options Dialog, where you can create your own. Let’s add a new code embedding to surround the selected code with the logging capabilities.

We will use the DXCore Log class located in the DevExpress.CodeRush.Diagnostics.General namespace (in the DevExpress.CodeRush.Common assembly). The embedded code will look like this (C#):

Log.Enter("Message");
try
{
  // selected text goes here...
}
catch (Exception ex)
{
  Log.SendException("An exception occurred", ex);
}
finally
{
  Log.Exit("Message");
}

1) Open up the Embedding options page:

CodeRush Embedding Options page preview

2) Switch to the C# language if it is not active:

CodeRush Embedding Options page Language

3) Click the Add Embedding button:

CodeRush Embedding Options New Embedding

4) Type the Name and Caption of the new embedding:

CodeRush Embedding Options Name and Caption

5) Leave the Style and other options as is, then fill the code embedding expansion area:

CodeRush Embedding Options expansion area

6) Add the required text commands to the expansion:

CodeRush Embedding Options expansion area text commands

That’s it. Let’s try to apply it (click the animation to enlarge):

CodeRush Custom Code Embedding preview

—–
Products: CodeRush Pro
Versions: 11.1 and up
VS IDEs: any
Updated: Sep/13/2011
ID: C132

Similar Posts: