Skip to Main Content
Visual Studio Hacks
book

Visual Studio Hacks

by James Avery
March 2005
Intermediate to advanced content levelIntermediate to advanced
304 pages
19h 23m
English
O'Reilly Media, Inc.
Content preview from Visual Studio Hacks
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft Visual Studio 2015 Unleashed, Third Edition

Microsoft Visual Studio 2015 Unleashed, Third Edition

Mike Snell, Lars Powers
.Net Framework Essentials

.Net Framework Essentials

Thuan L. Thai, Hoang Lam
C# 5.0 Unleashed

C# 5.0 Unleashed

Bart De Smet
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0596008473Errata Page