Skip Navigation Links



INotifyPropertyChanged Support in ReSharper 7

Author : Dmitri Nesteruk      Blog :JetBrains .NET Tools Blog      Date: 7/24/2012 12:26:50 PM


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:

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.

Bloggers

active bloggers in the last 24 hrs. Number shown in the bracket represents number of posts published in past 24 hrs,


other authors(104)

Firoze Shakir Photographerno1(8)

AMJAD KHAN(7)

MUNZ TDT(3)

pinksocks(3)

Sree(3)

Srinivasan Sampathkumar(3)

Abrachan Pudussery(2)

Aparna(2)

Artist ANIKARTICK(2)

Fidarose Isha(2)

mêlée(2)

mervin anto(2)

Nandana(2)

R.D. Bhalekar(2)

RWABhagidari.blogspot.com(2)

Sudhir(2)

Vandana Yadav(2)

Vikram Karve(2)

Aarthi(1)

Ajithkumar Krishnakumar(1)

amarllyis(1)

Amrutha Technologies(1)

ankush samant(1)

Anu Varma(1)

Anubhav Sharma(1)

Arti(1)

Binu Thomas(1)

Biswa Prakash(1)

Celvin Kattookaran(1)

Chandrika Shubham(1)

Chenthil(1)

churumuri(1)

Cynical(1)

daddysan(1)

Daksha(1)

Deboshree(1)

Dew(1)

Disha(1)

Divya Kudua(1)

DKD(1)

Dr.K.P.R.RAJA(1)

Esoterica(1)

Familycook(1)

Farida Rizwan(1)

FashionPhD(1)

Govind Kumar(1)

Hari Chandana P(1)

Hvvenugopal Haleyur(1)

Indrani(1)

Indrani(1)

Jahn n Style(1)

Javin Paul(1)

jay raj(1)

Jigish Shah(1)

Jon(1)

Kalyan P(1)

karanbhujbal(1)

Kaveri Venkatesh(1)

Kichu Khonn(1)

Krishna Rao(1)

Lakshmi(1)

Linuxos4all(1)

Manoje Nath(1)

Meena(1)

monikamanchanda(1)

Mosarrap H Khan(1)

Neelam Dadhwal(1)

Nisa Homey(1)

Nisheeth Ranjan(1)

nitya(1)

P.(1)

Padmanabha Vyasamoorthy(1)

Pooja Sharma Rao(1)

Pradeep Chakraborty(1)

Prahallad Panda(1)

Preeti Aghalayam aka kbpm(1)

Preety(1)

Raafay Awan(1)

Ranjith(1)

Ray Titus(1)

Renu(1)

RNA Corp(1)

Ruchi Gupta(1)

S. Anupam(1)

Sadhana Padmanabhan(1)

Sandra Jacob(1)

Sangeetha M(1)

Sanghamitra Bhattacherjee(Mukherjee)(1)

Santhosh Sivarajan(1)

Sassy Fork(1)

Sayan(1)

Shailza Sood Dasgupta(1)

Sharmila(1)

Shiva(1)

Shobha(1)

Shobhaa De(1)

Shruthi(1)

Shyam Bhatawdekar(1)

Simran(1)

Sriram Khé(1)

Srishti Aishwarya(1)

Srividya Ram(1)

Sujoy Das(1)

Suvrat Kher(1)

Tarang Sinha(1)

tikulicious(1)

Vidya lakshmi(1)

VJ Sharma(1)

wildflower(1)

winding river(1)


garland of Languages of India
an amalgamation of the diversified traditions
gracefully presented with novelty
http://www.haaram.com