Switch enum auto-fill

后端 未结 9 2042
故里飘歌
故里飘歌 2020-12-24 00:23

I was typing a switch with an enum in VS 2013 and all case statements filled out automatically after I finished the switch. Now I can\'t repeat it. I was not hallucinating,

相关标签:
9条回答
  • 2020-12-24 00:50

    VS 2019 + resharper create an empty switch with your variable. Click on first curly bracket "{" Then press alt + enter You will see Generate switch labels. Screenshot below:

    0 讨论(0)
  • 2020-12-24 00:53

    I think what you need is this:

    sw(tab)(tab)enumVariableName(tab)(downArrow)
    

    I tested it and works ( in VS2013 at least).

    0 讨论(0)
  • 2020-12-24 01:03

    Visual studio 2017, 2019 - without Resharper:

    1) write "switch"
    2) press two times TAB, then you will see:

    switch (switch_on)
    {
            default:
    }
    

    (the switch_on is highlited)
    3) retype switch_on to your enum variable or type
    4) press ENTER or click somewhere else (pressing TAB does not work), now you should see all the enum items filled:

    switch (YOUR_ENUM_VARIABLE_OR_TYPE)
    {
        case YOUR_ENUM_TYPE.Item1:
            break;
        case YOUR_ENUM_TYPE.Item2:
            break;
        case YOUR_ENUM_TYPE.Item3:
            break;
        default:
            break;
    }
    
    0 讨论(0)
提交回复
热议问题