The requested page is not available for the requested platform. You are viewing the content for Default platform.

C# and Visual Basic Embeddings

  • 5 min to read

This topic lists all the available Selection Embeddings for C# and Visual Basic.

try..catch

if ()

lock ()

Namespace¹

try..finally

if () else

block - {}

Stopwatch¹

try..catch..finally

while ()

TryCast(..)

To string¹

#region..#endregion

do..while ()

BeginUpdate..EndUpdate¹

commentbox¹

#if..#endif

using ()

WaitCursor¹

¹ The embedding is disabled by default. Use the Editor | All Languages | Selection Embeddings options page to enable it.


try..catch

Embeds a selection into the try..catch code block, and places the caret in the catch section.

try {
  // Embedded code
}
catch (Exception ex) {
}

A one-key action is available for this embedding. Enable the Selection | Embedding | C shortcut in the shortcuts configuration and use the "C" key to embed one or more selected lines into a try..catch block.


try..finally

Embeds a selection into the try..finally code block, and places the caret in the finally section.

try {
  // Embedded code
}
finally {
}

A one-key action is available for this embedding. Enable the Selection | Embedding | F shortcut in shortcuts configuration and use the "F" key to embed one or more selected lines into a try..finally block.


try..catch..finally

Embeds a selection into the try..catch..finally code block, places the caret onto the catch section, and drops a marker in the finally section.

try {
  // Embedded code
}
catch (Exception ex) {
}
finally {

}

A one-key action is available for this embedding. Enable the Selection | Embedding | T shortcut in shortcuts configuration and use the "T" key to embed one or more selected lines into a try..catch..finally block:


#region..#endregion

Embeds a selection between the #region and #endregion directives and selects the region name placeholder.

#region RegionName
// Embedded code
#endregion

This embedding is available using the Ctrl + 3 shortcut.


#if..#endif

Embeds a selection between the #if and #endif directives and places the cursor after the #if directive.

#if 
// Embedded code
#endif


if ()

Embeds a selection into the conditional block, selects the expression placeholder, and drops a marker after the block.

if (Expression) {
    // Embedded code
}


if () else

Embeds a selection into the conditional block with the else branch, selects the expression placeholder, and drops a marker in the else section.

if (Expression) {
    // Embedded code
}
else {

}


while ()

Embeds a selection into the while loop, selects the conditional expression placeholder, and drops a marker after the block.

while (Expression) {
    // Embedded code
}


do..while ()

Embeds a selection into the do..while loop and selects the conditional expression placeholder.

do {
    // Embedded code
} while (Expression);


using ()

Embeds a selection into the using () block, selects the object creation placeholder, and drops a marker after the block.

using (Expression) {
    // Embedded code
}


lock ()

Embeds a selection into the lock () block, selects the locker object placeholder, and drops a marker after the block.

lock (Expression) {
    // Embedded code
}


block - {}

Embeds a selection into the "floating" block (block without a parent statement).

{
    // Embedded code
}


TryCast(..)

Embeds a selection into the TryCast() function, selects the target type placeholder, and drops a marker after the statement.

TryCast(EmbeddedIdentifier, Type)

Embeddings Disabled by Default

BeginUpdate..EndUpdate

Embeds a selection into the BeginUpdate..EndUpdate method calls of an object from the clipboard. This embedding uses the «Paste» Text Command and requires an identifier in the clipboard.

«Paste».BeginUpdate();
try {
    // Embedded code
}
finally {
    «Paste».EndUpdate();
}


WaitCursor

Embeds the selection into the try..finally block, provided that the WaitCursor will be used during the selected code lines' execution. Creates linked identifiers for references to the saveCursor variable. Ensures that the System.Windows.Forms namespace is referenced.

Cursor saveCursor = Cursor.Current;
try {
    Cursor.Current = Cursors.WaitCursor;
    // Embedded code
}
finally {
    Cursor.Current = saveCursor;
}


Namespace

Embeds a selection into a namespace and selects the name placeholder.

Namespace MyNamespace
    ' Embedded code
End Namespace


Stopwatch

Measures the execution time of the selected code:

  • Creates a Stopwatch instance.
  • Creates linked identifiers for references to the stopwatch variable.
  • Starts the stopwatch before the embedded code.
  • Stops the stopwatch after the embedded code.
  • Outputs the stopwatch.Elapsed value to the console.
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
try {
    // Embedded code
}
finally {
    stopwatch.Stop();
}
Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);


To string

Quotes the selected code.

Before Embedding:

EmbeddedCode

After Embedding:

"EmbeddedCode"


Comment box

Embeds the selection into the comment box.

Before Embedding:

EmbeddedCode

After Embedding:

/* •———•
EmbeddedCode
   •———• */