Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I easily create a case (switch case) for all enum items?

Often I am using a switch-case, and creating a case for all enum items.

Is there a shortcut (it may well be a resharper shortcut) which creates all cases automatically and just let me fill the cases?

Or is this question related to code-snippet subject? Is it possible to create a dynamic code-snippet (it will vary according to enum type) ?

like image 263
serdar Avatar asked Jun 09 '14 07:06

serdar


2 Answers

Plain VS snippet will work for you ..write switch and press "TAB", write your enum type and press enter(twice), the cases will be generated for you.

like image 184
Prerak K Avatar answered Oct 17 '22 03:10

Prerak K


Set the cursor after the first brace within the switch statement and press Alt + Enter. You will see the option to generate switch labels.

like image 22
Jesse Petronio Avatar answered Oct 17 '22 02:10

Jesse Petronio