C# Code, Tutorials and Full Visual Studio Projects

Resharper Live Templates

Posted by on Jan 17, 2011 in Tips & Tricks | 1 comment

Resharper Live Templates

Those that use Resharper love it, those that don’t haven’t used it enough. It’s a great tool and once you start coding with it you’ll find it hard to live without.

I’ve created two Reshaper Live Templates that I use constantly and thought I would share them.

Download Templates

To install the templates just run Visual Studio 2010 and under the Resharper menu select Live Templates. On the toolbar press the Import button and select the XML you just downloaded. And they should be installed!

Dependency Property Live Template (dep)

Dependency properties are great, and if you do MVVM you’ll be typing them in a lot, so I created a resharper live template to do the work.

When you type “dep” and accept the template it will will enter in the Dependency Property syntax for you for you including the property.

public static readonly DependencyProperty $NAME$Property = DependencyProperty.Register("$NAME$", typeof ($TYPE$), typeof ($CLASS$), new PropertyMetadata($DEFAULT$));
$END$
public $TYPE$ $NAME$
{
    get { return ($TYPE$) GetValue($NAME$Property); }
    set { SetValue($NAME$Property, value); }
}

Some may question where I put the $END$ since it’s not at the end of the template. This is so that you can quickly enter these one after the other and have all your DependencyProperty lines one right after the other.

INotifyPropertyChanged Live Template (propn)

I do lots of databinding, and as such I find that I need to constantly type in properties. The new auto-property syntax is great but you can’t use it if you want your properties to support INotifyPropertyChanged. (I really hope Microsoft changes this.) ┬áSo after typing the properties in the long for for probably the billionth time I decided to create a Resharper Live Template to do it for me.

Just type “propn” to get the template, and it will create the property and the call to INotifyPropertyChanged for you.

private $TYPE$ $NAME$;
$END$

public $TYPE$ $NAME2$
{
    get { return $NAME$; }
    set
    {
        $NAME$ = value;
        if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("$NAME2$"));
    }
}

One Comment

Join the conversation and post a comment.

  1. kelias

    Sorry about that, the download button wasn’t working. Give it a go now.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>