
208
|
Chapter 6, Speed Hacks
#53 Create Connection Strings Quickly
HACK
Sub Macro1( )
Dim var As String = InputBox("Enter enum name")
DTE.ActiveDocument.Selection.NewLine( )
DTE.ActiveDocument.Selection.Text = _
"private void Record" + var + "( int value )"
DTE.ActiveDocument.Selection.NewLine( )
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine( )
DTE.ActiveDocument.Selection.Text = _
"BusinessLogicCall.RecordEnum( value, OurEnum." + var + " ) ;"
DTE.ActiveDocument.Selection.NewLine( )
DTE.ActiveDocument.Selection.Text = "}"
End Sub
Resulting code. In this example, you now have a macro that is useful for gen-
erating new versions of the Record function when new items are added to
the
OurEnum enumeration. This can be useful when providing a Business
Layer interface in which you wish to provide a distinct function for each
value of the enumeration.
If you type
NewValue into the InputBox prompt, the macro will create the fol-
lowing function:
private void RecordNewValue( int value )
{
BusinessLogicCall.RecordEnum( value, Enum.NewValue ) ;
}
—Ben Von Handorf
HACK
#53
Create Connection Strings Quickly Hack #53
Database connection strings can be tricky and confusing. Use a macro to
automatically generate your connection strings.
Connection strings are one of those things that you usually create only when
you are starting a new project or if you have to change databases, so it is