Randy Patterson

Code To Live, Live To Code

  • Home
  • About

12

Mar

ReSharper and the Method Group Refactor

Posted by randypatterson  Published in C#, ReSharper
While writing code similar to the following lines, ReSharper suggested the “Replace With Method Group” Refactoring for Line 2.
 
   1: var names = Directory.GetFiles(@"c:\Program Files").ToList();

   2: names.ForEach(n => Console.WriteLine(n));

The Method Group shorthand is usually found in places where you take the following code

myButton.Click += new EventHandler(myButton_Click);

and replace it with this.

myButton.Click += myButton_Click;

The C# compiler can infer the usage of the EventHandler class, giving you cleaner, less noisy code.

Letting Resharper apply the Method Group refactoring produces the following code.
   1: var names = Directory.GetFiles(@"c:\ProgramFiles").ToList();

   2: names.ForEach(Console.WriteLine);

 
I was pleasantly surprised by the results. Apparently, I don’t have to explicitly declare the intermediate lambda variable ‘n’ just so I can pass it into the WriteLine method. The compiler is smart enough to infer this for me.  Although a little confusing at first, this shorthand notation is pretty nice.  I doubt I would have realized this without ReSharpers’ refactoring suggestions, one of the many reasons I’m a R# Junkie.
Bookmark It

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone
Add to Google Bookmarks Add to reddit Add to Slashdot Add to Stumble Upon
Add to Technorati Add to Twitter Add to Yahoo My Web
no comment

4

Oct

Beginning ReSharper

Posted by randypatterson  Published in ReSharper

I’ve been using ReSharper for nearly 2 1/2 years now and I can’t imagine trying to program without it.  However, one of the greatest challenges to being productive with ReSharper is learning the daunting list of keys.  Many of the Resharper features are highly discoverable using visual indicators such as icons “squiggly” lines but most refactoring and navigation activities require memorizing numerous key presses….or does it?

Refactor This

There are dozens of key presses used for Navigating and Refactoring your code and many are only valid in certain contexts.  For Example, it doesn’t make sense to attempt the Introduce Variable (Ctrl+Alt+V) refactor when your cursor is on a method signature.  Fortunately, ReSharper has an aggregate key press that will show you all of the refactorings appropriate for the current context. 

image

You no longer have to remember that Ctrl+F6 allows you to change a method signature you simply remember to press  Ctrl+Shift+R and select the Change Signature refactor.

image

As you can see “Refactor This” shows all the refactorings appropriate for the current context but it also includes the key presses for the ones that have mappings.  As you find yourself using certain items over and over you will slowly remember those keys and learn them at your own pace.  Furthermore, those refactorings that do not have a mapping are still available using this aggregate key. I often use “Pull Members Up” to “pull” a new method into the class’s Interface saving me time from the tedious cut and paste. This is a huge win for discoverability as I would never have known this refactoring existed without “Refactor This”.

Navigate From Here

ReSharper offers an aggregation key for Navigating your code that is just as powerful as Refactor This.

image

 

image

Using these two keys you gain access to most of what ReSharper has to offer and allows you to discover which Refactoring and Navigation features you like most, without the hassle of learning everything first. 

Now What

When beginning ReSharper there are a few steps I highly recommend.

  1. Download the ReSharper Key Map file
  2. Print the Key Map and hang it near your monitor where you can easily find it
  3. Highlight the “Navigation From Here” and “Refactor This” keys
  4. Highlight a few other important keys so you can quickly locate them when needed

 

Below is a link to the ReSharper map containing keys I find most useful highlighted for you.

 

Bookmark It

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone
Add to Google Bookmarks Add to reddit Add to Slashdot Add to Stumble Upon
Add to Technorati Add to Twitter Add to Yahoo My Web

Tags: ReSharper

1 comment

13

Jul

Resharper Tip #1 – Highlight Usages

Posted by randypatterson  Published in C#, ReSharper

I just love ReSharper (R#) by JetBrains, it has substantially increased my productivity while writing, and navigating code.

Quickly highlight all usages of a symbol within the current file.   To use,  place your cursor on the Type or Variable that you want to highlight then press Shift+Ctrl+F7

Highlight Usages

The Write operations are highlighted in light Red and the Read operations are highlighted in light Blue.  Pressing ESC removes the highlights. Furthermore, the R# Marker Bar to the right of your code uses to same colors to highlight all usages in the current file.  Just click on the horizontal mark to quickly navigate to the usage.

image

Bookmark It

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone
Add to Google Bookmarks Add to reddit Add to Slashdot Add to Stumble Upon
Add to Technorati Add to Twitter Add to Yahoo My Web

Tags: ReSharper

1 comment

RSS

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Tags

Azure CodeCamp IoC Podcast Presentation ReSharper TFS Unit Test Unity VS2010

Categories

  • C# (8)
  • Deals (2)
  • Events (11)
  • Patterns (4)
  • Podcast (5)
  • ReSharper (3)
  • TFS (1)
  • Uncategorized (7)
  • Unit Tests (1)
  • Unity Application Block (7)
  • What Burns Me (1)

Recent Posts

  • Support The National Day of Prayer
  • ReSharper and the Method Group Refactor
  • Moved my Blog
  • Installing VS 2010 in XP Mode
  • TFS Basic Version

Twitter

  • RT @dotnetblogs: #shanselman: A New Podcast for Developers - This Developer's Life http://ow.ly/18RfJQ-2 hours ago
  • going to go see vampires suck with my daughter. I'll have to laugh when she does because I wont understand a thing-3 days ago
  • WIndows Live Sync is the new Live Mesh http://tcrn.ch/ceh2oR-4 days ago
  • got a signed copy of @sdorman new C# book!!-1 week ago
  • RT @devfish: tampa/orlando web firestarters - http://bit.ly/9opxrF #fldev-1 week ago
  • I am constantly impressed with the quality and content of the RadioLab Science poscast http://bit.ly/Od4Ek-1 week ago
  • Reality is frequently inaccurate - Douglas Adams-1 week ago
  • Reminder: IASA Meeting tonight: @absolutdeno presenting Delivering SOA with Silverlight and WCF RIA Services http://bit.ly/aRCSuc-1 week ago

Comments

  • olegsych on Moved my Blog
  • Ed Holloway on TFS Basic Version
  • Jeff P on The Power of the Predicate<T>
  • Jeff Odell on Beginning ReSharper
  • Jeff Odell on POCO and Unity Application Block Part I

Recent Entries

  • Support The National Day of Prayer
  • ReSharper and the Method Group Refactor
  • Moved my Blog
  • Installing VS 2010 in XP Mode
  • TFS Basic Version
  • Windows Azure Commercial Release this year!
  • Orlando Code Camp 2009 – Unity Presentation Slides and Code
  • Speaking at the South Florida Code Camp
  • Call for Speakers
  • Beginning ReSharper
  • Random Selection of Posts

    • The Power of the Predicate<T>
    • Resharper Tip #1 – Highlight Usages
    • POCO and Unity Application Block Part I
    • Welcome
    • Useless Unit Test
    • Tampa User Group Meeting for October
    • 10 Podcasts Every Developer Should Listen To
© 2008 Randy Patterson. WordPress. Free email sender software
Theme designing by Mark Hoodia