Blogs

Rory Becker - DevExpress CodeRush Blog

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:
SuitEnumerationVB

…and you declare a variable of that type…

SuitVariableVB

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.

SuitEnumerationPreExpansion

  • Hit space to expand the template.

SuitEnumerationPostExpansion

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.

Published Apr 07 2011, 12:43 PM by
Bookmark and Share

Comments

Mark Harby

That is awsome.

April 7, 2011 12:05 PM

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.

April 11, 2011 3:44 PM

Rory Becker - DevExpress

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

April 12, 2011 7:13 AM
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2014 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners