INotifyPropertyChanged Support in ReSharper 7

Let’s see what’s good in ReSharper 7 in addition to support for Visual Studio 2012 and WinRT development.

Ever since the release of Windows Forms, the INotifyPropertyChanged interface has been used by developers to allow properties to notify whoever needs to know (typically, the UI) that they have changed. Support for change notification, which nowadays appears in many core (WPF, Silverlight) and third-party frameworks, has been frequently requested on the ReSharper issue tracker and, in the 7.0 release, we are happy to oblige. Here’s what we’ve got in store.

Automatic implementation

As soon as you indicate that a class implements INotifyPropertyChanged, ReSharper offers a quick-fix that not only implements the interface members, but also provides a default implementation of the method as well as the needed event.

With the interface implementation in place, you can navigate to a property and convert it to a field+property declaration that calls the notification method. The property can be an auto-property or a field-backed property provided the assignment to the backing field is the last expression in the setter.

If you have fields instead of properties, you can also invoke the Generate|Properties action, and ReSharper offers the option to generate properties matching those fields with the required change notifications:

Important note: in order to get context actions related to an implemented INotifyPropertyChanged interface to show up, code annotations need to be added to the project. You can find the default implementation in ReSharper|Options|Code Annotations. These annotations contain the definition of the [NotifyPropertyChangedInvocator] attribute, which is used to decorate the method that is responsible for firing the event. Also note that this is only necessary if you’re implementing INotifyPropertyChanged yourself, and is not required if you are inheriting from a framework class that implements it.

Tracking Symbol Names

Referring to a property by name is not the safest way of doing things, but if you have to do it, ReSharper has got your back. First, ReSharper keeps a close eye on those property names for you. Should you make a mistake in a name or, for instance, refer to a property declared private, ReSharper will complain about it:

In addition, when you decide to call OnPropertyChanged manually, ReSharper will offer a completion list for that string parameter.

Framework Support

Not all implementations of INotifyPropertyChanged are identical. Third-party application frameworks often have their preferred way of notifying on property changes, and are shipped with corresponding base classes that framework users are encouraged to inherit from. One major difference is that certain frameworks prefer to use a lambda expression instead of a string literal as a parameter to the notification method.

ReSharper 7 supports the following frameworks out of the box:

  • MVVM Light (WPF 3 and 4; Silverlight 3, 4 and 5; Windows Phone 7 and 7.1)

  • Caliburn.Micro (WPF 3 and 4; Silverlight 4 and 5; Windows Phone 7.1)

  • Prism (WPF 4; Silverlight 4)

  • Catel (WPF 3 and 4)

  • MVVMHelpers (WPF 3 and 4, only lambda expressions supported)

What this means in practical terms is that if you were to inherit from, say, Prism’s NotificationObject, when it comes to generating properties you actually get a choice of which RaisePropertyChanged method the implemented properties will call:

If we pick the lambda-driven implementation, our properties will be defined similar to the following:

And, of course, this choice will correspondingly be presented in the property-altering context actions:

As you can see, ReSharper is attuned to the specifics of the parents of the containing class, and is capable of presenting all of the available choices.

Comments below can no longer be edited.

29 Responses to INotifyPropertyChanged Support in ReSharper 7

  1. Avatar

    Alex says:

    July 24, 2012

    What about DependencyProperty? I would say its a biggest pain to deal, as there is a lot of potential copy-paste errors arise 🙂

  2. Avatar

    Dmitri Nesteruk says:

    July 24, 2012

    @Alex what kind of features would you like ReSharper to provide with respect to dependency properties?

  3. Avatar

    Jura Gorohovsky says:

    July 24, 2012

    @Alex I second Dmitri’s question. As of now, R# only provides a built-in live template to generate dependency properties

  4. Avatar

    Alex says:

    July 24, 2012

    wuut, how come i didn’t know that.
    I’m using currently the GammaXaml R# plugin ( It has neat feature, that if your declaration if DependencyProperty changes it will mark those as error (type changed, or Name is changed)
    But yeah, in this case, its easier just delete all and create from scratch using live template 🙂

  5. Avatar

    Corrado Cavalli says:

    July 24, 2012

    I’m running R#7 Beta but can’t see the feature, is it in a newer release?

  6. Avatar

    Julien Lebosquain says:

    July 24, 2012

    Nice and awaited feature. It was the main reason I started develop GammaXaml in the first place 🙂

    @Corrado: you have to annotate your RaisePropertyChanged or equivalent method with the new R# [NotifyPropertyChangedInvocator] if you’re not using one of the framework listed in this blog post.

  7. Avatar

    duile says:

    July 24, 2012

    Hi, What about C# 5 Caller Information support?

  8. Avatar

    Dmitri Nesteruk says:

    July 24, 2012

    @duile at the moment, ReSharper does not support this mechanism. I have created a feature request for it — please feel free to vote for it.

  9. Avatar

    duile says:

    July 24, 2012

    Thanks @Dimitri. I have voted it.

  10. Avatar

    Jura Gorohovsky says:

    July 25, 2012

    Please feel free to create a feature request on this.

    Speaking of Jesse Liberty, he’s not really our own )

  11. Avatar

    Joe Reynolds says:

    July 25, 2012

    How easy will it be to implement a plug-in or something to use our own implementation of NotifyPropertyChanged with Resharper? In CODE Framework (my company’s framework, in the interest of full disclosure), you inherit from a “ViewModel” base class, then do something like the following:

    private string _someString;
    public string SomeString
    get { return _someString; }
    _someString = value;

    Will Resharper pick up on the fact that “NotifyChanged” is the implementation of INotifyChanged, instead of “OnPropertyChanged”? Will there be some sort of configuration available for this?

  12. Avatar

    Julien Lebosquain says:

    July 25, 2012

    @Joe: see my previous comment, you just have to annotate NotifyChanged with the attribute [NotifyPropertyChangedInvocator] from JetBrains.Annotations to make R# recognize your method.

  13. Avatar

    Joe Reynolds says:

    July 26, 2012

    Great! Thanks!

  14. Avatar

    Jason says:

    August 8, 2012

    How do you enable this feature? I don’t get that option on my resharper 7!

  15. Avatar

    Dmitri Nesteruk says:

    August 8, 2012

    @Jason: you need to annotate the event-firing method with the [NotifyPropertyChangedInvocator] attribute. You can get this attribute by pasting code annotations into your project – see ReSharper|Options|Code Annotations.

  16. Avatar

    snort says:

    August 16, 2012

    I’m not seeing any of this support in VS2010 + Resharper 7. Is this a VS2012 only feature?

  17. Avatar

    controlflow says:

    August 20, 2012

    @snort, this feature not only VS2012 feature, it works even in VS2005. Looks like you missing R# code annotation on event-firing method.

  18. Avatar

    controlflow says:

    August 20, 2012

    @SledgeNZ, [CallerMemberName] support is already implemented and will be publicly available in next minor release. Thx for your feedback!

  19. Avatar

    alexfdezsauco says:

    September 4, 2012

    For Catel developers we also provide a R# plugin

  20. Avatar

    Marcus says:

    September 17, 2012

    Nice feature, but you should really just point everyone to use NotifyPropertyWeaver. Free, simple, and results in significantly cleaner code. Once you’ve tried it you’ll never go back!

  21. Avatar

    Lukas says:

    September 24, 2012

    I already annotated my caller method with the [NotifyPropertyChangedInvocator] attribute, but i still can’t make this work…

    What am i doing wrong?

    Where’s my method:

    protected virtual void OnPropertyChanged(string propertyName)
    PropertyChangedEventHandler handler = this.PropertyChanged;
    if(handler != null)
    handler(this, new PropertyChangedEventArgs(propertyName));

  22. Avatar

    Lukas says:

    September 24, 2012

    Nevermind. It was there, but instead of a combobox it was a check button XD

  23. Avatar

    elmanaw says:

    May 8, 2013

    I’m using Resharper 7 and MVVM Light. When I use class ViewModelBase in which its super class is ObservableObject which implements INotifyPropertyChanged, so therefore in my view model its inherited the implementation and events.So I should be able to alt+insert to insert properties that implement INotifyPropertyChanged, currently I dont seem to be able to and I’m having to do this manually. What am I doing wrong?

  24. Avatar

    xoofx says:

    August 16, 2013

    @elmanaw I have the exact same problem. Created an issue here

  25. Avatar

    jeremy simmons says:

    December 22, 2013

    for the love of everything good and right, i just wasted 90 minutes of my life figuring out this simple thing.

    move the caret/cursor to THE NAME OF THE PROPERTY, not on the accessibility modifier (public/private/protected) at the beginning of the property

  26. Avatar

    Alex says:

    October 7, 2014

    On R# this feature doesn’t work.
    I derive my class from another one which in it’s turn implements INPC.

  27. Avatar

    Ash Wolford says:

    January 12, 2016

    Not getting the appropriate options in the alt+enter menu here either. ‘to property with backing field’ but no INPC-related things. Would also be nice to be able to refactor to custom implementations somehow, such as MVVMLight’s simpler Set(ref _backingField, value); method.

  28. Avatar

    Boleslav says:

    August 14, 2018

    Hey Resharper guys!
    Are there any news with this issue?
    It still seems actual. I’ve even created a related post in stackoverflow:
    Any hints?

Discover more