To use, open Macro Explorer and copy and pasteinto an existing or new macro project. To run a macro place the cursorat the required insertion point in your document and double-click thename of the macro in Macro Explorer. You may wish to define moreconvenient keyboard shortcuts for each macro via the Tools | Customizemenu.
Imports EnvDTE
Imports System.Diagnostics
Public Module CSharp
' Description: Inserts for loop
Sub ForLoop()
DTE.ActiveDocument.Selection.Text = "for (int i = 0; i < ; i++)"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 3)
DTE.ActiveDocument.Selection.CharRight(False, 19)
End Sub
' Description: Inserts while loop
Sub WhileLoop()
DTE.ActiveDocument.Selection.Text = "while ()"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 3)
DTE.ActiveDocument.Selection.CharRight(False, 6)
End Sub
' Description: Inserts do-while loop
Sub DoWhileLoop()
DTE.ActiveDocument.Selection.Text = "do"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "} while ();"
DTE.ActiveDocument.Selection.CharLeft(False, 2)
End Sub
' Description: Inserts foreach loop
Sub ForEach()
DTE.ActiveDocument.Selection.Text = "foreach ( in )"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 3)
DTE.ActiveDocument.Selection.CharRight(False, Image may be NSFW.
Clik here to view.
End Sub
'Description: Inserts if block
Sub IfNoElse()
DTE.ActiveDocument.Selection.Text = "if ()"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 3)
DTE.ActiveDocument.Selection.CharRight(False, 3)
End Sub
' Description: Inserts if-else block
Sub IfElse()
DTE.ActiveDocument.Selection.Text = "if ()"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "else"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 7)
DTE.ActiveDocument.Selection.CharRight(False, 3)
End Sub
' Description: Inserts switch block
Sub Switch()
DTE.ActiveDocument.Selection.Text = "switch ()"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "case :"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "break;"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "case :"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "break;"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "default:"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "break;"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, Image may be NSFW.
Clik here to view.
DTE.ActiveDocument.Selection.CharRight(False, 7)
End Sub
' Description: Inserts generic exception block
Sub Exception()
DTE.ActiveDocument.Selection.Text = "try"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "catch (System.Exception ex)"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 5)
End Sub
End Module