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.

[button link=”/downloads/resharpertemplates.xml” type=”icon”]Download Templates[/button]

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$));
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$;

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

Categories:   Code


Sorry, comments are closed for this item.