Using ReSharper with Silverlight

ReSharper is a great tool for developer productivity.  I absolutely can't live without it!  If you haven't already tried ReSharper, you should do yourself a favor and go download it now.  It takes a while to get used to, but once you grok the features (namely the keyboard shortcuts), you will see how powerful this tool really is.

Ok enough with the testimonials, how can you take advantage of ReSharper when working on Silverlight projects?  If you have ever used Resharper, you may know that it has a great feature called Templates.  Templates give you the ability to quickly generate code that you would generally need to write by hand.  There are three different types of templates in ReSharper:

  • Live Templates - Allow you to generate code within the context of an existing file.
  • Surround Templates - Allow you to "surround" selected code with a pre-defined template.
  • File Templates - Allow you to quickly generate an entire file from a pre-defined template.

I've built 4 templates that you can use in your Silverlight endeavors.  Below you will find a short description of each:

Dependency Property Generation

Let's face it, it takes a lot of code to declare a dependency property.  I have created a Live Template that will automate almost all of the work for you.  As illustrated in the screen capture below, you simply type DependProp in the editor, supply a property name and type, then hit tab and you have a fully defined dependency property!

 DependencyPropertyTemplate


Visual State Manager Block Template
The Visual State Manager Block Template is similar in function to the Dependency Property template, but this template will build a VisualStateManager declaration within the context of an XAML file.  To use the template, simply type vsm while editing an XML/XAML file.  The usage for this template is very similar to the DependProp template.

Generic.xaml File Template
As a Silverlight control developer, you may find it annoying to have to define the generic.xaml file over and over again.  Using a File Template, we can quickly build standard declaration and ReSharper will help you fill out the rest. To generate a new Generic.xaml file, press ALT+R+N+G, enter a name for the template and then click OK.

image 

image

Control File Template
The Control File Template will construct a basic class that inherits from Control and includes the DefaultStyleKey in the constructor. The usage for this template is the same as the Generic.xaml file template above.

Installing the Templates
To import these templates, select the File Templates tab in the ReSharper Templates Explorer.  Click the import button and select the SilverlightFileTemplates.xml file,then click ok. 

image

Importing the Live Templates is very similar.  Select the Live Templates tab in the ReSharper Templates Explorer.  Click the import button select the SilverlightLiveTemplates.xml file, then click Ok.


Conclusion and Download
I’d be interested in hearing any suggestions for these templates,  Also, if you have built any ReSharper templates that you find useful, please let me know!  My goal is to find and add the most useful ReSharper templates and add them to Silverlight Contrib.

In the meantime, you can download them here:
Download Resharper Templates


Feedback

# re: Using ReSharper with Silverlight

Gravatar Thanks for these templates. Another one I can think of top of my head is the INotifyPropertyChange template... 12/1/2008 7:59 PM | Petar

# Silverlight Cream for December 01, 2008 -- #443

Gravatar In this issue: Alex Golesh, Silverlight SDK, John Stockton, Page Brooks(2), Mike Snow(2), Terence Tsang 12/2/2008 1:20 AM | Community Blogs

# re: Using ReSharper with Silverlight

Gravatar I use ReSharper since a long time and it works better and better. You can save a lot of time, use it!

Peter Löbel 12/3/2008 2:24 AM | Silverlight Travel

Comments have been closed on this topic.