Is there a way to generate the INotifyPropertyChanged helper with Resharper after having implemented the interface?

时间:2015-06-15 14:41:41

标签: c# resharper inotifypropertychanged

I have several classes that implement the INotifyPropertyChanged interface.

I'm now using Resharper and want to add the following standard code snippet to these classes:

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
    var handler = PropertyChanged;
    if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}

The simplest solution I found so far is to delete the

public event PropertyChangedEventHandler PropertyChanged;

and implement the interface again, this time with the helper. Is there an easier way?

1 个答案:

答案 0 :(得分:1)

如果您在属性上按Alt+Return,您将有机会创建帮助程序。

Screenshot 注:鼠标已超过PropertyChanged