ReSharper Help and Tutorial

I have found that for me, ReSharper wasn't even close to as great a help until I changed my operating basis regarding how I write code. Many times there are many subtle things you do differently, which just causes pain with ReSharper. It also wasn't easy for me to find and remember all the key combinations. To this day when I can't remember, I just open the Tips it gives during start up and just cycle through them until I find the one I am looking for. (Definately not expeditious since they have a cool PDF reference card now).

So I thought I would write up a quick tutorial on the functions I use most and give some help to those that may not of discovered them or found them not to be as useful.

Optimize Usings

Before:

It highlights in gray any using's that aren't being used.

After:

I love de-cluttering and absolutely hate how I find other peoples code declarations (especially in ASP.NET after the designer adds a bunch of stuff you don't reference in the code behind).

Surround With

This is the problem that had me shaking me head. When I code, a lot of time I don't know I need a particular statement until after I write the line of code. It would cause me so much lost time deleting and moving code around. So if I have:

x = 29;

and then I realize I need an “if” surrounding my statement, I would start typing the “if” and as soon as I hit the enter key after the line, it would insert the {} after my “if”, but BEFORE my code, like:

if (x == 0)
{}
x = 29;

What I really wanted it to do was:

if (x == 0)
{
x = 29;
}

This is where the “Surround With” feature comes in. Highlight your code (in my case x = 29;), Hit Ctrl+Alt+J, and choose “if”. You get:

if ()
{
x = 29;
}

and then it puts the cursor between the paranthesis to do your “x == 0” check.

And of course, you can also define your own “Surround with” macros. I made a few no brainer ones for conversions:

All I do is highlight the “29”, hit Ctrl-Alt-J, hit the “A” key and:

x = Convert.ToInt32(29);