Jeffrey Palermo (.com)

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Bread and butter Resharper (demo) - level 300
I've been using Resharper full-time for a year.  I'd dabbled with it before then, but I didn't learn enough to get the full benefit.  I want to thank Steve Donie and Jeremy Miller for helping me to learn the full featureset of the product.  I can't imagine coding without it now.  I'm using Resharper 2.0 (with VS 2003 as well as VS 2005), and I'm not going to talk about what features are different from 1.5 because v1.5 has all the features I will talk about here. 

  

Resharper is a refactoring tool, yes, but that seems to be a small portion of it.  It is an overall productivity tool.  It does some code-generation, some fill-in-the-blank, some extract method/variable, some move method, some create method/property/constructor, and a whole lot of helping you with the job of programming.  You can certainly use the mouse with this tool if you wish, but the shortcut keys make me so productive on the keyboard that I don't have to slow down and reach for the mouse.

  

I'm going to go over the features that I use.  I've created a test project using the Movie application that comes as an example in VS 2005.  This is not an exhaustive list, and it isn't every dialog, but I use these all the time.  Every screenshot is inside Visual Studio in the code window.  Here is the menu for Re#er.  It has the standard things.

 

  

Optimize usings

You'll notice in the screenshot that two using statements are grayed out.  These are unnecessary.  There is no code that requires these.  They are visual noise.  Let's get rid of them.  CTRL+ALT+O

 

 

Reformat code

Resharper has so many formatting options that (if it's important to you) you can share settings with the team so that all code looks uniform.  But that not all there is.  Re#er will include optimize usings, shorten System.DateTime to DateTime, remove unnecessary "this" keywords and put your "virtual public void" back to "public virtual void" (if you have a boneheaded programmer that left it like that). CTRL+ALT+F

 

  

Find code file

Why go for the solution explorer when you know the class you want.  Just start typing, and Re#er will narrow down the list as you type.  You can take a shortcut and type "*Tester" to find all your NUnit classes.  CTRL+N

 

  

Find file

Now you need to open one of your NHibernate mappings, but it's not a code file.No problem.      Just narrow down from all files.  CTRL+SHIFT+N

 

  

Find usages

How many times have you wondered how many classes in your solution are calling a particular method on IConfiguration.  Is it used at all?  How much?  Do you have any hope to change it without major regression?  Find out who is using it easily and jump right to the usage, all from the code window.  CTRL+ALT+F7

 

Context-sensitive refactoring

You will typically know what you want to do, and Re#er will be there waiting for you.  Stick the cursor on a member name and choose from the refactorings available there.  One of my favorites is "Change Signature".  It makes it easy to add an extra parameter to a class constructor, and Re#er will add it in all the places where that constructor was used.  CTRL+SHIFT+R

 

  

Error analysis

Ever wondered if you needed to clean up the class a bit?  Re#er keeps a running tab on errors and warnings in the upper-right hand corner of the code window.  When things are good, it will stay green.  It's always there.

 

  

Find subclass

You know you need to go to your default implementation of IConfiguration.  You know, the one that actually reads from app.config?  Your entire application uses IConfiguration since you don't want to tightly-couple to the app.config file.  Sometimes you just want to pop over to whoever implements the interface or inherits from a class.No problem.      Place the cursor on the interface (or class) name and find who inherits.  CTRL+ALT+B

 

  

Context help

Wherever you are, if Re#er can help, it will show you a yellow lightbulb or pop up a suggestion.  If you like what it shows you, give Re#er the go ahead and continue without missing a beat.  in this case, I need to add a using statement.  Isn't it annoying to stop your flow just to go up to the top to adding a using?  Now you don't have to.  With all the context-sensitive helps, and whenever there is a lightbulb, just press:  ALT+ENTER

 

  

Line-level refactoring

The red lightbulb is a context-sensitive help that is also a warning.  Go ahead and fix the error quickly (or just let Re#er do it for you).  In this case, I really wanted to match up types, but I made a mistake.  ALT+ENTER

 

Live templates

These are like code snippets but much simpler, and they have been a Re#er feature for a long time, so just because VS 2005 has a similar feature that is harder to use doesn't mean that I should stop using my templates.  I have created templates for common things like creating a new NUnit test fixture and a test method.  In this example, I have typed "foreach", and Re#er awaits to take it from there.  Here is a before and after.  CTRL+J

 

  

Name suggestions

I always call my IDomainRepository "repository" when using it in a method.  I like descriptive variable names, but it takes more typing. . . but not with Re#er.  After the type name, just ask Re#er for a name.  Pick from the list.  CTRL+SPACE

  

Show Class Members

When you are in a class you want to remember what is there and jump to it quickly.  Use Re#er to move around quickly.  CTRL+F12

 

  

Recent files

If you want to jump between files that you have recently opened, just pull up the list and arrow down to the one you want.  CTRL+E

 

  

Dead code detection

If code is dead, delete it.  It's never a good idea to save code for a rainy day.  It just pollutes the codebase.  Re#er will color it gray for you.  Let it help you keep the codebase clean. 

 

  

Generate Code

I saved this one for last because it's my favorite one.  This is a micro-code-generator.  It will create a property/constructor, etc exactly the way I would have typed it.  In that case, why do I want to type it.  Imagine this:  You have a new domain class with 8 fields.  Do you really want to type those 8 boring properties and a constructor?  I don't.  A few shortcut keys, and the class is done.  ALT+INSERT




[tags: programmer, programming, resharper, jetbrains, productivity, c#, .net, vs2005, visualstudio]


Posted 08-02-2006 9:01 PM by Jeffrey Palermo
Filed under:

[Advertisement]

Comments

Ben Scheirman wrote re: Bread and butter Resharper (demo) - level 300
on 08-02-2006 2:30 PM
I'm so glad you posted this!  I've been using resharper for a few weeks now and I couldn't sit and open the docs to learn all of this stuff.
DotNetKicks.com wrote Bread and butter Resharper
on 08-02-2006 7:29 PM
You've been kicked (a good thing) - Trackback from DotNetKicks.com
Gill Cleeren wrote re: Bread and butter Resharper (demo) - level 300
on 08-04-2006 8:23 AM
A very comprehensive listing you've got here.

I posted a link on my blog too since this is very interesting reading material!
Fowlbot wrote re: Bread and butter Resharper (demo) - level 300
on 08-05-2006 6:44 PM
Great overview of ReSharper. I took umbrage at this statement, though:

>>You have a new domain class with 8 fields.  Do you really want to type those 8 boring properties and a constructor?

Why automate a violation of encapsulation? No one should instantly generate accessor / mutator methods until there is no alternative, as this leads quickly to Law of Demeter violations and the Dark Side.
Jeffrey Palermo wrote re: Bread and butter Resharper (demo) - level 300
on 08-06-2006 10:44 AM
Fowlbot,
Your caution is warranted, and you would certainly take good design into account when using R# to generate chosen accessors.
Noah Coad's Code wrote Articles + Posts to Check Out
on 08-16-2006 2:58 PM
When I see a blog post or article that I want to read, investigate, follow up on, etc, I jot it down...
joeyDotNet wrote Get on the JP Train
on 08-16-2006 11:28 PM
joeyDotNet wrote Get on the JP Train
on 08-16-2006 11:29 PM
One of the bloggers I've really been following lately is Jean-Paul Boodhoo, formerly a Senior Developer...
ISerializable - Roy Osherove's Blog wrote 16 Features in Resharper Every Developer Needs To Learn
on 08-27-2006 10:28 AM

Jeffery has a nice list of the features in Resharper he uses most often in his daily coding. The list

Ole wrote re: Bread and butter Resharper (demo) - level 300
on 08-28-2006 2:21 AM
Excellent list! However, you forgot one: Smart complete. Say you have the following: XmlDocument doc = new | Press SHIFT+CTRL+SPACE to get: XmlDocument doc = new XmlDocument(); It works in all sorts of places (method call parameters, assignments, enum expansions, etc.). It even understands and suggests static factory methods: int n = | Press SHIFT+CTRL+SPACE to get: int n = Int32.Parse(|); Cool stuff...
PhilloPuntoIt wrote Resharper 2.0.1 disponibile
on 08-29-2006 6:07 AM
Zupancic Perspective wrote Great R# Feature Walk-Thru
on 08-30-2006 5:19 PM
Jeffrey Palermo [C# MVP] wrote Resharper (R#) 3.0 has been released!
on 06-21-2007 6:38 PM

Version 3.0 of my favorite IDE add-in has been released. If you purchased v2.5 recently, you get a free

Greg Smith wrote re: Bread and butter Resharper (demo) - level 300
on 02-24-2008 10:47 PM

Interesting article!

Thanks..

Links Today (2008-03-12) wrote Links Today (2008-03-12)
on 03-12-2008 11:19 AM

Pingback from  Links Today (2008-03-12)

Yuanjian wrote Interesting Finds: 2008.03.13
on 03-12-2008 10:17 PM

Other: Imdb Services - search movies by code,title,actors,directors,etc on imdb.com Web: ProtoFlow: Coverflow

gOODiDEA wrote Interesting Finds: 2008.03.13
on 03-12-2008 10:18 PM

Other:ImdbServices-searchmoviesbycode,title,actors,directors,etconimdb.comWeb:ProtoFlow...