开发者

Visual studio 2010 Switch statement generation by enum

开发者 https://www.devze.com 2023-01-09 19:34 出处:网络
Is there any way to get generation of switch statements开发者_JAVA百科 by enum? For example if I have big enum and I have method with has parameter enum, then I need to code switch statements for eac

Is there any way to get generation of switch statements开发者_JAVA百科 by enum?

For example if I have big enum and I have method with has parameter enum, then I need to code switch statements for each case, but is there a way to generate this switch statement by enum?

If I have a lot of other enums if my enums wide range and if I have 10-100 methods with different enums parameters in that case switch coding became a hell.

Probably it is good idea to create t4 template, anyway I am happy to hear any suggestions about enum switch generation.

Looking for solution without any additional software like Resharper.


Visual Studio already does this. Type switch, tab to complete that snippet, type the enum name and you'll get the case statement autogenerated.


Visual Studio does this with a snippet.

Type switch, press Tab and then enter the name of your enum variable, and press Enter.

You should get a switch statement with each enum member case'd.


Tried messing with both of the above answers and couldn't get it to work for me. The big difference I found is that you have to double tap Tab after you start typing switch.

A single tab will complete the switch statement but won't open up parentheses. By double tapping it will open up paratheses and leave your cursor in the middle, so when you start typing the enum variable and tab to autocomplete it, you will generate all of the switch statements.

0

精彩评论

暂无评论...
验证码 换一张
取 消