views:

125

answers:

2

Is there any way to get generation of switch statements by enum

For example if i have big enum and i have method witch 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 heve a lot of another 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 hearany suggestions about enum switch generation.

Looking for solution without any additional software like Resharper.

+6  A: 

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

here's a video showing this in action: http://www.onesoft.dk/post/Using-the-switch-code-snippet-with-an-enum.aspx

nos
+3  A: 

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.

Neil Moss