wpf - Editing Resharper's INotifyPropertyChanged -


when have class declare implements inotifypropertychanged interface, resharper automatically generate implementation:

public event propertychangedeventhandler propertychanged;  [notifypropertychangedinvocator] protected virtual void onpropertychanged(string propertyname) {   var handler = propertychanged;   if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } 

which editing this:

public event propertychangedeventhandler propertychanged = delegate { };  [notifypropertychangedinvocator] protected virtual void onpropertychanged(string propertyname) {    propertychanged(this, new propertychangedeventargs(propertyname)); } 

can somehow edit autogenerated code? resharper's documentation less clear me on this.

no, can't edit auto-generated code, because needs handle number of possibilities when generating - e.g. c# 6 uses ?. operator, , needs handle when event exists , has been initialised.

if want use shorthand version doesn't have local variable , null check, can create event first, , initialise = () => { }; before generating onpropertychanged method. however, best keep local var + null check, thread safety.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -