Quick-Fixes help generate switch blocks

Mikhail Kropotov

This post is just a simple tip that barely begins to touch on the added convenience of ReSharper’s on-the-fly code analysis and the usefulness of Quick-Fixes.
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.
Writing a switch statement
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:
Press Alt + Enter for available quick-fixes
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.
The switch labels are generated
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.

Comments below can no longer be edited.

4 Responses to Quick-Fixes help generate switch blocks

  1. Shea says:

    June 14, 2006

    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.

  2. Obfuscator says:

    June 16, 2006

    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.

  3. Development on a Shoestring says:

    July 6, 2006

    .NET Development tools

    Ian Olsen’s ReSharper vs. CodeRush post (and it’s subsequent follow-up). He makes some very useful points about the two programs. After my ReSharper demo licence expired recently I really empathise with this point:
    I really miss ReSharp…

  4. Dennis says:

    October 31, 2016

    Recently installed Resharper (v2016.2.2), but thew switch auto-fill does not work.


Subscribe to .NET Tools updates