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
Post a Comment