Microsoft 9GD00001 Computer Accessories User Manual


 
368 Microsoft 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 12-3, all of the namespaces that begin with EnvDTE have code that allows
you to manipulate the VS environment. The macro itself is a Sub within a Module.
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 re-record the entire macro. For example, what if you missed a keystroke
or misspelled something? You can just edit the code, save the file, close the Macro editor,
and then re-run the macro. In fact, there is a problem with the macro for C#; it will only