Click here to Skip to main content
15,878,871 members
Articles / Programming Languages / Visual Basic
Article

Productivity macros for C# in Visual Studio 2005

Rate me:
Please Sign up or sign in to vote.
4.55/5 (8 votes)
13 Mar 2007Public Domain4 min read 73.7K   557   40   11
How to automate typical routine coding tasks in C# with the help of macros

Introduction

This is a Visual Studio 2005 macro project which is intended to automate typical coding routines.

What's new?

Version 0.1.3

  • Enhanced type parser, now it parses types of any complexity (nested generics, multi-arrays, etc.)
  • "Word" macro now works with generic types
  • New "BaseConstructors" macro has been added

Installation

To enable the GapeUpon macros, you have to follow the steps:

  1. Open Visual Studio 2005
  2. Go View -> Other Windows -> Macro Explorer (or press Alt + F8).
  3. In the Macro Explorer panel Right click at the Macros node.
  4. In the context menu click the Load Macro Project... item.
  5. In the Add Macro Project Window specify where the gapeupon.vsmproj file from this package is

How to use the GapeUpon macros

After loading expand the GapeUpon -> Development nodes in the Macro Explorer panel.
You can see the following macros:

  • BaseConstructors
  • GenerateConstructor
  • GenerateProperties
  • GuardConditions
  • Quotes
  • Undone
  • Word

Right click -> Run or Double click on any macro to run it.

Binding macros to the keyboard

Some macros like "Quotes" and "Word" are extremely helpful only when they are bound to the keyboard.

To bind a macro to the keyboard do the following:

  1. Go Tools -> Options...
  2. In the Options window go Environment -> Keyboard3
  3. Type gapeupon into the Show commands containing field
  4. Select a macro from the list below
  5. To assign shortcut keys for the selected macro place the cursor into the Press shortcut keys field and press desirable combination of keys on the keyboard which you want the macro to be bound to
  6. Press OK

Description

This section provides a quick review on what each macro does and how it could be applied.

BaseConstructors

Creates a set of constructors which correspond to the constructors of a base class if any. When we inherit a class from some base class which has a number of constructors we have to do a lot of work redeclaring our constructors in the way they conform with the constuctors of the base class. We have to feed all the base constructors with the parameters they require. This macro creates constructors redeclaring and passing parameters to the base constructors.

HOW TO RUN: Place cursor anywhere inside of the class and run the macro.

GenerateConstructor

Creates a parameterized constructor each parameter of which corresponds to a private field of the class.

HOW TO RUN: Place cursor anywhere inside of the class and run the macro.

GenerateProperties

Generates properties for each private field which does not have a corresponding property yet.

HOW TO RUN: Place cursor anywhere inside of the class and run the macro.

GuardConditions

Creates guard conditions for a method. If method takes a parameter of the reference type in most cases it must be checked for being not null before use. Otherwise you are likely to get the "NullReferenceException" error.

HOW TO RUN: Place cursor anywhere inside of the method and run the macro.

Quotes

Cycles the insertion of various types of quoted string. Simplifies putting variables into a string constant.

HOW TO RUN: Make sure the macro is bound to the keyboard (see "Binding macros to the keyboard" above). Keep hitting the macro's shortcut keys when you are editing a string constant and want to put quotes into it.

Undone

Places a #warning directive inside a method you want to finish later. This directive reminds you each time when the project is being compiled by throwing out a compilation warning.

HOW TO RUN: Place cursor anywhere inside of the method and run the macro.

Word

Cycles variants of a variable's name based on the name of its type. Quite often the name of the variable is a part or the whole name of its type, so when we declare the variable we have to do the same work twice. This macro eliminates the routine work of naming variables.

HOW TO RUN: Make sure the macro is bound to the keyboard (see "Binding macros to the keyboard" above). Enter a type of a variable you want to declare and then hit the shortcut keys number of times.

See also

To see the current status and get latest releases, to report a bug or submit a feature, I request you to visit the GapeUpon project page at SourceForge.Net. I appreciate any feedback.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
United States United States
C# .NET developer since 2003

Comments and Discussions

 
QuestionWhy did you call it GapeUpon? Pin
cjmos25-Mar-10 0:27
cjmos25-Mar-10 0:27 
QuestionHow do you create a .vsmproj file? Pin
SirGnip30-May-09 2:21
SirGnip30-May-09 2:21 
AnswerRe: How do you create a .vsmproj file? Pin
Aleksey Bykov30-May-09 14:23
Aleksey Bykov30-May-09 14:23 
GeneralRe: How do you create a .vsmproj file? Pin
SirGnip30-May-09 15:24
SirGnip30-May-09 15:24 
GeneralRe: How do you create a .vsmproj file? Pin
Aleksey Bykov30-May-09 17:32
Aleksey Bykov30-May-09 17:32 
AnswerRe: How do you create a .vsmproj file? Pin
SirGnip1-Jun-09 4:45
SirGnip1-Jun-09 4:45 
QuestionMacros not working Pin
Peeyush1198-Apr-08 0:56
Peeyush1198-Apr-08 0:56 
NewsMore macros Pin
Dan Handevik13-Mar-07 14:05
Dan Handevik13-Mar-07 14:05 
GeneralRe: More macros Pin
Aleksey Bykov14-Mar-07 3:45
Aleksey Bykov14-Mar-07 3:45 
GeneralVisual Studio 2003 Pin
pinturic13-Mar-07 6:12
pinturic13-Mar-07 6:12 
Very nice project i have used with visual studio 2005; however i still have many solutions that I mantain in visual studio 2003 and for many reasons i am not going to convert them to the new ide version.

Does a version of your plugin exist that can be run in visual studio 2003 or is it complex to "downgrade" it ?
I see it is written in VB.NET which I don't know at all!

Thank you veru much!
GeneralRe: Visual Studio 2003 Pin
Aleksey Bykov14-Mar-07 3:40
Aleksey Bykov14-Mar-07 3:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.