简体   繁体   English

如何轻松为所有枚举项创建案例(切换案例)?

[英]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. 我经常使用一个switch-case,并为所有enum项创建一个case。

Is there a shortcut (it may well be a resharper shortcut) which creates all cases automatically and just let me fill the cases? 是否有一个快捷方式(它可能是一个resharper快捷方式)自动创建所有案例并让我填写案例?

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) ? 是否可以创建动态代码片段(它会根据枚举类型而有所不同)?

普通VS片段将为你工作..写switch并按“TAB”,写你的枚举类型并按Enter键(两次),将为你生成案例。

Set the cursor after the first brace within the switch statement and press Alt + Enter. 将光标置于switch语句中的第一个括号后面,然后按Alt + Enter。 You will see the option to generate switch labels. 您将看到生成开关标签的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM