Ticket T419779
Visible to All Users

CodeRush for Roslyn switch code template does not seem to generate cases for enums

created 9 years ago

If I start with a function like
void DoStuffWith(System.Drawing.Imaging.PixelFormat value)
{

}

and want to different things depending on the value passed in, I might put my cursor on the blank line and type:

sw<tab><tab>val<enter><enter>

If I do this with CodeRush's switch templates disabled, I get this expansion:
switch (value)
{
    case System.Drawing.Imaging.PixelFormat.Indexed:
        break;
    case System.Drawing.Imaging.PixelFormat.Gdi:
        break;
    case System.Drawing.Imaging.PixelFormat.Alpha:
        break;
// … Eliding remaining enum values for brevity.
    default:
        break;
}

If I do this with CodeRush's switch code templates enabled, I get this expansion instead:
switch (value)
{
    case 0:

break;
}

I see that CodeRush for Roslyn has three switch code templates, and one of them has an "HasEnum" tag in in. How do I get that template selected for enums?

Answers approved by DevExpress Support

created 9 years ago

Hi Dale,
CodeRush templates work differently than Visual Studio snippets.With CodeRush, you need to copy the variable/parameter name you want to use in the 'sw' template into the clipboard first. If the clipboard contains a valid enum value, you will get expansion of the switch construction with all possible case statements. Please see the video:
http://screencast.com/t/oU1GGPHB9

    Comments (2)

      That's completely backwards. I shouldn't have type the condition I'm testing and then stuff it on the clipboard before I type switch.

      That design failure aside, it's still not working correctly. Given this code:

      enum ExternalCommunicationLicense { None, Development, Staging, Production }
      static class LicenseCheck {
          public static ExternalCommunicationLicense GetExternalCommuncationLicense() { /* Implementation irrelevant*/ }
      }
      class TestClass
      {
          void Method()
          {
              sw
          }
      }

      Put "LicenseCheck.GetExternalCommuncationLicense()" on the clipboard and then press tab after sw above. When I try this, I still get the non-enum switch expansion.

      With Visual Studio's expansions, I get the expected enum-form expansion after typing or pasting the function call.

      AE AE
      Alex Eg (DevExpress) 8 years ago

        Hello,

        I've created a separate ticket on your behalf (Templates - The 'sw' template doesn't work correctly on being used with the method call argument). It has been placed in our processing queue and will be answered shortly.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.