CodeRush Tip– Create a Select / Switch statement with branches for each element of an enumeration

“Is there a way in CodeRush to auto-fill a SELECT CASE statement with the available enumerations ?”

I was just asked this question on Twitter and because it was such a reasonable question, I figured I’d share the wealth in a more permanent way by posting the answer on my blog.

Ok so imagine you have an Enumeration with 4 elements:

…and you declare a variable of that type…


What you need to do is

  • Copy the name of that variable to the clipboard.
  • Type either select or switch (depending on your language of choice).

Update: You don’t even have to type all of the characters in select or switch. There are even shorter aliases. Type either se<space> or sw<space> for the same effect.


  • Hit space to expand the template.


CodeRush will generate a switch or select statement, with branches for each of the potential value of your enumeration variable.

Additionally CodeRush will place Markers in each of these branches, so that you can sequentially hit Escape to jump to each of them in turn, and insert whatever code you feel is appropriate.

Free DevExpress Products – Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We’ll be happy to follow-up.
Mark Harby
Mark Harby

That is awsome.

7 April 2011
Michael Stortz
Michael Stortz

It would be nice it the expansion code supported some kind of interrupt (Esc, perhaps).  I've done this once with an enum that had a couple of hundred values; it took a minute.

11 April 2011
Rory Becker - DevExpress
Rory Becker - DevExpress

@Michael We'll have the devs look into this perf issue. Thanks for the report.

12 April 2011
Ernie Zahn
Ernie Zahn

This used to work, but is no longer working.  I am using VS 2015 CR version

Pressing space bar does nothing, hitting TAB two times puts the variable name in brackets


24 February 2016

Please login or register to post comments.