C# and Visual Basic Embeddings
- 5 minutes to read
This topic lists all the available Selection Embeddings for C# and Visual Basic.
1 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.
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.
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.
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.
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 ()
Embeds a selection into the conditional block, selects the expression placeholder, and drops a marker after the block.
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.
while ()
Embeds a selection into the while loop, selects the conditional expression placeholder, and drops a marker after the block.
do..while ()
Embeds a selection into the do..while loop and selects the conditional expression placeholder.
using ()
Embeds a selection into the using () block, selects the object creation placeholder, and drops a marker after the block.
lock ()
Embeds a selection into the lock () block, selects the locker object placeholder, and drops a marker after the block.
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.
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:
After Embedding:
Comment box
Embeds the selection into the comment box.
Before Embedding:
After Embedding: