
368Microsoft Visual Studio 2010: A Beginner’s Guide
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module RecordingModule
Sub ValidateStringParameter() DTE.ActiveDocument.Selection.WordLeft() DTE.ActiveDocument.Selection.WordRight(True) DTE.ActiveDocument.Selection.CharLeft(True) DTE.ActiveDocument.Selection.Copy() DTE.ActiveDocument.Selection.EndOfLine() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "if" DTE.ExecuteCommand("Edit.InsertTab") DTE.ExecuteCommand("Edit.InsertTab") DTE.ActiveDocument.Selection.Text = "string.IsNullOrEmpty(" DTE.ActiveDocument.Selection.Paste() DTE.ActiveDocument.Selection.Text = ")" DTE.ActiveDocument.Selection.LineDown() DTE.ActiveDocument.Selection.Text =
"throw new ArgumentNullException(""" DTE.ActiveDocument.Selection.Paste() DTE.ActiveDocument.Selection.Text = """, """
DTE.ActiveDocument.Selection.Paste()
DTE.ActiveDocument.Selection.Text =
"value is not valid."")" DTE.ActiveDocument.Selection.LineDown() DTE.ActiveDocument.Selection.NewLine()
End Sub
End Module
In Listing
Each of the statements corresponds to the steps used to create the macro in the preceding section. For example, the Find And Replace window has several options, which this macro populates, regardless of whether they contribute toward the purpose of the macro.
Opening a macro in the editor can be very useful if you want to make a quick change, without needing to