Whidbey C#: Expansions Rock!

Looks like I am going for a Whidbey theme tonight. One of the nice features in Whidbey is expansions. An expansion is a simple string preceded by a magic keystroke (CTRL-T,X) which is a shortcut for writing more complex code. In the example below I am using the shortcut for defining a read-write property.

Once you select the expansion, you can press enter and some code will be injected into the source file at the cursor location. This code is templated with the modifyable fields highlighted in yellow (by default I guess). You can press tab to navigate around the fields and change the text. Related source in the template can be configured to change.

I’m currently investigating how this can be extended, there are a few ones that I use for diagnostics which could replace a few of the macros that I have written.

Update: In the course of my investigations I have learnt that there is an even better shortcut than typing CTRL-T,X, in the case of the property, just type in “prop” and hit TAB twice. I’ve found the definitions for the built in expansions in the following directory.

C:\Program Files\Microsoft Visual Studio 8\VC#\Expansions\1033\Expansions

The XML file structure is fairly easy to understand – I’ll follow up with a more indepth analysis based on what I see.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s