PIRATED 20130914 1659

PIRATED 20130914 1659

NOTE: This content appears to have been plagiarized. Please leave a comment or email tnwiki at Microsoft (with a link to this article) if we are mistaken. The content was pulled from the following source:
The community rules state:
  • "Someone else has relevant content and you want to help them share it with the world. It's a nice thought, but do not copy other people's content to the Wiki, even if the owner said it was OK."

INotifyPropertyChanged Support in ReSharper 7

Tuesday, July 24th, 2012

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 inReSharper|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 INotifyPropertyChangedyourself, 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.


This is copied from JetBrains blog

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
  • Carsten Siemens edited Revision 2. Comment: Pirated Content - see my comment

  • XAML guy edited Revision 1. Comment: added reference to original

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
  • XAML guy edited Revision 1. Comment: added reference to original

  • Carsten Siemens edited Revision 2. Comment: Pirated Content - see my comment

  • NOTE: This article was reported as Pirated/Plagiarized Content (content you didn't write) and will be removed. Please do not steal content from others. If you feel we are mistaken, please leave a comment or email tnwiki at Microsoft with a link to this article and with clear and detailed reasons why you own the content or have explicit permission from the author.

    Content was taken from: "INotifyPropertyChanged Support in ReSharper 7"

    Published by Dmitri Nesteruk on July 24th, 2012


Page 1 of 1 (3 items)