For example, implement INotifyPropertyChanged
interface:
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
handler.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Two things:
- Copy event to local variable to prevent errors with multithreading (here are some examples). Resharper gives notification, if you don't copy to local variable:
- Check it for null, to prevent
NullReferenceException
But now, we can use ?.
operator for null-checking. And if I use it, Resharper is idle:
So, question is: should I copy event ProperyChanged
to local variable, if I use null-conditional operator?