Quick-Fixes help generate switch blocks

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.

This entry was posted in ReSharper Tips&Tricks and tagged . Bookmark the permalink.

3 Responses to Quick-Fixes help generate switch blocks

  1. Shea says:

    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:

    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. Pingback: Development on a Shoestring

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>