4

in CodeRush, is there a way to auto-fill a SELECT CASE statement with the available enumerations ?

So, given this enum declaration (or one with a lot more enumeration options)

Public Enum eMailTransmissionMethods
    unknown = 0
    IIS
    AutoEmailer
End Enum

I want to build the following framework.

    Select Case method
        Case eMailTransmissionMethods.IIS
        Case eMailTransmissionMethods.AutoEmailer
        Case eMailTransmissionMethods.unknown
    End Select
cometbill
  • 1,619
  • 7
  • 19
  • 41

2 Answers2

6

Simply:

  • Copy the identifier name to the clipboard
  • Type either select or switch (depending on your language of choice VB.Net vs C#)
  • Hit the space bar

CodeRush works out the type of the identifier on the clipboard, and creates a branch for each value that the enumeration can hold.

Another, more complete, version of this answer is detailed here on my blog complete with pics

Rory Becker
  • 15,551
  • 16
  • 69
  • 94
  • 1
    In C#, you can also enter "sw" followed by the space bar on an empty line (after copying the identifier to the clipboard). And in VB you can enter "se" followed by the space bar, saving you four keystrokes. – Mark Miller Apr 07 '11 at 14:12
5

In addition to the template, if you have Refactor! bundled with your CodeRush installation, you can use the "Create Case Blocks from Enum" refactoring, which allows you to build a select case statement. It is available in the reference or local (parameter) declaration of the enumeration type.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • +1 I bow to superior knowledge. Although in fairness you're cheating. You have the source code right in front of you :P – Rory Becker Apr 07 '11 at 14:11