Quick-Fixes help generate switch blocks

The following example was lifted off ReSharper Early Access Program newsgroup where users can discuss their experience with the latest builds of ReSharper. By the way, we’re about to release a bugfix update, so don’t change the channel.

Consider the following setup. You need a switch statement for an enum variable.

As soon as you type the braces of the switch block, a Quick-Fix becomes available which can generate the appropriate switch labels for you. You could ask, “What is there to fix?” as you are meaning to supply them by hand, anyway. Programming by intention or not, the Quick-Fix is there and it can save you some time, so why not use it?

Press Alt + Enter to bring up the available quick-fixes (just one in this case), then select the right one:

Immediately after, the case stubs are generated for you. All values of the enumerated type are included and a break statement is supplied for you to add to.

There are lots of this kind of things available in Quick-Fixes and Context Actions (new in ReSharper 2.0). We’re going to talk about those pretty soon.

Please send in your suggestions for post topics and requests for tips and tricks. We’ll listen.

3 Responses to Quick-Fixes help generate switch blocks

While ReSharper drastically improves programmer productivity (I used the rate of 15% to convince my non-technical manager…), I find I most profit from the ability to catch common programmer errors (e.g., Array.Cop doesn’t exist) before the compilation cycle. I feel like less of a failure when my syntactical errors are caught by ReSharper than by the compiler. The compiler is alot meaner than ReSharper in the sense that when you make a mistake in the sense that all implications of that mistake are brought to your attention (it’s like if you lose a bunch of money in the stock market and you’re forced to immdiately see yourself on the bus instead of the BMW, AND your wife leaving you). Whereas ReSharper only lets you know of the problem locally, not globally. Much more pleasant.

Hi Shea,
I can relate to that and, actually, a number of our own developers would agree with you a 100%. This goes hand in hand with the idea of “developing with pleasure” which we’ve always advocated and promoted.