Pablo Picasso
"Computers are useless. They can only give you answers."
My Latest Tweets
Tags

This will be shown to users with no Flash or Javascript.
Calendar
<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Sign in

So Visual Studio 2010 has this cool new feature called Reference Highlighting. If you don’t know anything about it yet, go and read the excellent Visual Studio Tips & Tricks blog to find out how to use it. What Zain Nabousi’s post doesn’t say however is that you can also customize the color of the highlighted symbols:

  1. Go to Tools > Options > Fonts and Colors.
  2. Select Text Editor in the Show settings for dropdown.
  3. Select Highlighted Reference from the Display items list.
  4. Change the item foreground and background to your preferred colors.

Reference Highlighting

Now when the cursor is place on a field for example, all references are highlighted as shown below and you can navigate between them using Ctrl + Shift + Down/Up Arrows.Visual Studio highlighted referenceNote that to remove the highlight, you need to move the cursor away from the field.

ReSharper has had a similar functionality since as far as I can remember - that is since at least version 3. To activate it press Shift + Alt + F11 and use Ctrl + Alt + Page Up/Down to move between the highlighted references. But, as usual, ReSharper goes one step further by highlighting where the symbol is being used (blue by default) or set (pink by default). ReSharper also places a coloured and clickable marker in the vertical margin that corresponds to the symbol’s usage within the file. To remove the highlighting simply Escape.ReSharper highlighted referenceThat’s it!

A lot of Developers who have never seen ReSharper in action often do not appreciate how much more productive they could be if they would start using it. Their arguments for not trying it out usually ranges from “I don't want to rely on a tool to do my coding” to “Why should I use R# when Visual Studio is already doing most of what I want/need” or “I don't like R# telling me what to do”. While these can be easily refuted, I think the main issue is that learning the tool itself can be a bit daunting at first. There are a lot of shortcuts to remember, options to set and functionality to digest. It also means adapting the way you work with the IDE and unlearn some old habits.

So if you are one of these reluctant Developers or just want to become a R# Jedi but don't know where to start, here is my advice: Learn the three shortcuts that rule them all... and the rest will follow!

1. Navigation

Navigation shortcut Navigation options

 

2. Code Generation

 Code generation shortcut Code generation options

3. Refactoring

 Refactoring shortcutRefactoring options

Note that all the options displayed are context sensitive and depend on where the caret is placed. Hence you will get different menu items based on whether your cursor is on a class, a method, etc.

I have been coding with ReSharper since version 3.0 and I simply can't work without it. It is IMO a must-have productivity tool and because of that I have encouraged any .NET Developer I work with to start exploring its capabilities by learning these three shortcuts. So far none of them have gone back to using plain vanilla Visual Studio. Hopefully if you break down the learning curve this way, you will also reap the benefits of what some people have called “the best IDE for Visual Studio”!

…Bonus Shortcuts: Go to type and Go to file.

Search shortcuts

Creating Extension Methods only takes a few steps with ReSharper :

1. Declare your intent

First tell ReSharper what you want to do. Note that in the line below, I have specified a local variable and an input parameter for the method to create. This will allow ReSharper to infer both the return type and the method parameter type.

Declare your intent  

 
 
2. Create static class

With your cursor on “StringExtensions”, press ALT + Enter (if you are using the Visual Studio shortcut keyboard bindings). In the Context Actions dialog, choose “Create static class” and press enter.

Create static class 

 ReSharper will generate the new class for you.

New StringExtensions class

 

3. Create method

Move your cursor to the method for which you want to generate the Extension Method. Open again the Context Actions dialog, select the first option and press enter.

Create method 

The method is automatically added to the new class.

New method

 

4. Static to Extension Method

Finally we need to convert our new static method to an Extension method. Highlight or set the cursor on the static method to convert, then open the “Refactor This” menu (Ctrl + Shift + R). Choose the last item to complete the process.

Convert Static to Extension Method   

ReSharper will not only refactor the method’s signature to add the ‘this’ keyword but also replace the original line to use the new Extension Method.

result

All you have to do now is to focus on the new method’s implementation.

Now in action:R# in Action: Creating Extension Methods Note: The screencast is heavily edited as my Dev machine simply can’t cope with Visual Studio and Camtasia running at the same time.

“Progress is made by lazy men looking for easier ways to do things”
Robert A. HeinleinW (American science-fiction writer, 1907-1988)

Let ReSharper do the work!