generate case statement in switch
I remembered that resharper can generate all the case statement
for an empty switch statement when the switch target is type of enum.
but I don't how to do that?
for example, variable v is type of enum E, and enum E has two value A, B.
when I have the following code:
switch(v)
{
}
resharper will suggest to generate following code:
switch(v)
{
case E.A:
break;
case E.B:
break;
}
thanks!
Please sign in to leave a comment.
btw: i am using newest EAP for vs 2003.
There should be a warning on switch braces that tells you about empty switch.
A lightbulb should appear if you put the cursor on the braces. Pressing alt+enter
(or whatever shortcut is assigned to opening lightbulb menu) should bring
the option to generate case labels.
You can also submit a request to our tracker if you wish this action to be
available on non-empty switch or on any other place beside the empty switch
block.
Best regards,
Andrey Simanovsky
" There should be a warning on switch braces that tells you about empty switch.
A lightbulb should appear if you put the cursor on the braces. Pressing alt+enter
(or whatever shortcut is assigned to opening lightbulb menu) should bring
the option to generate case labels. "
Right, this is what I was talking about. It doesn't have a warning and lightbulb in the empty switch. And there is nothing appear after I pressed altenter. (altenter works in other places) I am using build 267.
live template issue: I defined "psrs" as "public static readonly string".
however when I type psrs and tab, it expands the content in two lines:
public static readonly
string
is there any settings that goes wrong?
I just installed build 267 yesterday.
Try unchecking "Reformat" checkbox for this template.
Valentin Kipiatkov
CTO and Chief Scientist
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
That works.Thanks!
anyone has same problem on the empty switch issue? it still doesn't working :(
Is there any an alternative way to generate all case statement?
Thanks!
Hello,
We appreciate your feedback.
The corresponding JIRA request has been created, and you are welcome to monitor
its status at http://www.jetbrains.net/jira/browse/RSRP-33668.
Best regards,
- Development Team.
thanks. I did more testing. It works fine with enum that already define in .net framework. But it doesn't work for any enum that I defined in my own projects. Hope this helps.
Probably, your enums have too many items. There is a limitation on number
of items in the enums, for which the fix is available. If it is an obstacle,
we can drop this limitation.
Best regards,
Andrey Simanovsky
Look like this is the reason, my enum has many items. What is the limit now? is there anywhere I can set or it is hard coded? I really need this feature, not only it save lots of time, but also make sure the completeness.
Thanks!!
Unfortunately, the current value (32) is hard-coded. We will change it to
something bigger and store it in xml with user settings so that you can configure
it if it is not big enough. The change will go in 2.5.1.
At present, to test switch completeness you can try to use smart-completion.
Type "case " inside switch on expression with enum type and press CtrlShiftSpace
(or another shortcut you have assigned to Smart Type Completion). If there
are unmatched enum values they will be suggested in the completion list.
Best regards,
Andrey Simanovsky
Is there any chance that the change will also be on the version for vs.net 2003?
Thank you!