July 14, 2008

ReSharper – A Class Creating Machine

Filed under: Development — Tags: — Darrin Maidlow @ 7:43 am

Recently, I purchased a copy of .  I’m not even going to pretend I’ve scratched the surface of what ReSharper can do, but I can assure you it’s a massive time saver when creating classes from scratch.  I’m furiously plugging away, implementing an ORM for RADE, and to do that I needed to create a lot of classes pretty much from scratch (oh, and do I have a few things to say about that, but that’s for another day).  Let’s look at a simple example.  To get things started, create a new class.  Select the folder in the solution explorer, and press Alt+Insert:

ReSharper Class Creation

Press enter and you are prompted for the class name.  So Visual Studio has this of course, but this is a small example of some of the time savings you can achieve.  Enter the class name and you start off with an empty class.  Next, lets define a couple of private members.   Let’s run with the following example.

   1: namespace RADE.BO.Domain
   2: {
   3:     public class SampleClass
   4:     {
   5:         private Int32 _ID;
   6:         private String _Description;
   7:         private Int64 _BiggerInt;
   8:     }
   9: }


Simple class.  Three member variables.  Here is where the big time savers come in.  Next, click Alt+Insert again and you will be prompted with the following options:

Some ReSharper Code Generation Tools

Choose Properties.  You will now be given the option to select one or many fields, set the access rights, read only and virtual properties as well a bunch of others. 

ReSharper Properties Generator

Execute that and all of your get/sets are defined.  My one complaint is that ReSharper is not maintaining the type on the properties.  My Int32′s become int, and Int64′s become long’s.  Apparently this is slated to be fixed.  

So yes, this sample class is tiny, but the time savings on larger classes, or projects full of classes are significant.  The last feature I’ve been using extensively in this project is the generate constructor tool.  Again, a form is displayed with the defined properties, select the ones you want and boom.  You can create half a dozen different constructors in seconds.  I’ve created a full object model on, roughly 20 different mildly complex objects in less than an hour, around midnight on a Sunday =)

Some of the other things ReSharper does is suggest code cleanup ideas by removing unused directives, easy execution of , improved code completion.  I encourage you to check it out, .

Technorati Tags:

1 Comment »

  1. [...] I’ve mentioned ReSharper in the past – but I had to bring it up again..  Version 5 has some great new functionality [...]

    Pingback by ReSharper 5.0 is coming! « Geospecialling — April 2, 2010 @ 5:33 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Switch to our mobile site