private bool raiseBeforePropertyValueChangesEvent(PropertyValueChangeEventArgs evntArgs) { var evntHndlrs = BeforePropertyValueChanges?.GetInvocationList(); if (evntHndlrs == null) { return(true); } foreach (var evntHndlr in evntHndlrs) { var handler = (BeforePropertyChangingEventHandler)evntHndlr; var result = handler(this, evntArgs); if (result == false) { return(false); } } return(true); }
/// <summary> /// 属性通用的setter方法 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <param name="property"></param> /// <param name="propertyName"></param> protected virtual void set <T>(ref T property, T value, [CallerMemberName] string propertyName = "") { propertyName.ShouldNotBeNullOrEmpty(); #endif if (!Equals(property, value)) { if (BeforePropertyValueChanges != null || AfterPropertyValueChanged != null) { var oldvalue = property; var evntArgs = new PropertyValueChangeEventArgs(propertyName, oldvalue, value); bool allowChanging = raiseBeforePropertyValueChangesEvent(evntArgs); if (!allowChanging) { return; } setvalue(ref property, value, propertyName); raiseAfterPropertyValueChangesEvent(evntArgs); } else { setvalue(ref property, value, propertyName); } } }
private void raiseAfterPropertyValueChangesEvent(PropertyValueChangeEventArgs evntArgs) { AfterPropertyValueChanged?.Invoke(this, evntArgs); }