Usability, MVC, ASP.NET

28. March 2008 00:32
by Henrik Stenbæk
0 Comments

Using the switch code snippet with an enum

28. March 2008 00:32 by Henrik Stenbæk | 0 Comments

I just had one of those WOW experience today when I happened to use the switch code snippet with an enum.

I had an enum like this:

   1:  enum MyEnum
   2:  {
   3:      value_1,
   4:      value_2,
   5:      value_3,
   6:      value_4,
   7:      value_5
   8:  }

Start the video to se what happened when I tapped out of the snippet "switch_on" field.

WOW the snippet automatically created:

case MyEnum.value_1:
    break;

for each element in the enum. But how did it do that? Looking into the switch.snippet file I found:

<Literal Editable="false">
    <ID>cases</ID>
    <Function>GenerateSwitchCases($expression$)</Function>
    <Default>default:</Default>
</Literal>

 

It's the GenerateSwitchCases function that's doing the job - one out of 3 pre defined functions that available to "snippets"

Comments are closed