INotifyPropertyChanged Support
The INotifyPropertyChanged
interface is widely used in .NET applications to send notifications when a property has changed its value. ReSharper provides a set of features that help you implement this interface.
ReSharper helps implement property change notification for the following frameworks:
MVVM Light (WPF, Silverlight, Windows Phone, Universal apps)
Caliburn.Micro (WPF, Silverlight, Windows Phone, Universal apps)
Prism (WPF; Silverlight, Windows Phone)
Catel (WPF, Silverlight, Windows Phone, WinRT, ASP.NET MVC)
MVVMHelpers (WPF 3 and 4, only lambda expressions supported)
First of all, ReSharper detects that the INotifyPropertyChanged
interface is being used and provides a special quick-fix to put the required implementation in place.
After applying the quick-fix, ReSharper generates a method for property change notification and prompts you to provide a name for this method.
As you can see in the illustration above, the generated method is marked with the [NotifyPropertyChangedInvocator] attribute, which enables full support of the INotifyPropertyChanged
interface, which includes adding change notifications to properties, validation and completion for property names in string literals, navigation to properties, support in refactorings and code generation. It is recommended to add ReSharper annotation attributes to your project before you generate the implementation.
If there are some properties in your class that do not notify about changes, you can easily transform them into properties with change notification using the corresponding context action (which is only available if the notification method is decorated with the [NotifyPropertyChangedInvocator]
attribute):
When you generate properties for existing fields, and there is a method decorated with the [NotifyPropertyChangedInvocator]
attribute, you will be able to select the Notify on property changes checkbox in the Generate dialog to get properties with change notification:
Also, ReSharper provides code inspections and code completion for the arguments passed to the OnPropertyChanged
method.
ReSharper takes advantage of Caller Info attributes when it implements INotifyPropertyChanged in .NET Framework 4.5 projects. It also helps migrate to CallerMemberName-based implementations by highlighting redundant arguments and suggesting a quick-fix.