Visual Studio 2010 通过枚举生成 Switch 语句 [英] Visual studio 2010 Switch statement generation by enum

查看:45
本文介绍了Visual Studio 2010 通过枚举生成 Switch 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过枚举生成switch语句?

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

例如,如果我有一个大枚举并且我有一个带有参数枚举的方法,那么我需要为每种情况编写 switch 语句,但是有没有办法通过枚举生成这个 switch 语句?

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?

如果我有很多其他枚举,如果我的枚举范围很广,并且如果我有 10-100 个具有不同枚举参数的方法,那么在这种情况下,开关编码就变成了地狱.

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.

创建 t4 模板可能是个好主意,无论如何我很高兴听到有关枚举开关生成的任何建议.

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

寻找没有任何其他软件(如 Resharper)的解决方案.

推荐答案

Visual Studio 已经这样做了.键入 switch、tab 以完成该片段,键入枚举名称,您将自动生成 case 语句.

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 2010 通过枚举生成 Switch 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆