/// <summary> /// Implement this method to execute your handler processing. /// </summary> /// <param name = "input">Inputs to the current call to the target.</param> /// <param name = "getNext">Delegate to execute to get the next delegate in the handler /// chain.</param> /// <returns> /// Return value from the target. /// </returns> public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { object newValue = null; object oldValue = null; BindableModelObject bindableObject = null; if (input.MethodBase.Name.StartsWith("set_")) { string propertyName = input.MethodBase.Name.Substring(4); newValue = input.Arguments[ValueParameter]; var propertyInfo = input.Target.GetType().GetProperty(propertyName); oldValue = propertyInfo.GetValue(input.Target, null); bindableObject = input.Target as BindableModelObject; } var nextDelegate = getNext()(input, getNext); if (bindableObject != null) { ProcessChanges(bindableObject, newValue, oldValue); } //if return(nextDelegate); }
/// <summary> /// Processes the changes and invokes the NotifyPropertyChanges event on Self property. /// </summary> /// <param name="bindableObject">The bindable object.</param> /// <param name="newValue">The new value.</param> /// <param name="oldValue">The old value.</param> private void ProcessChanges(BindableModelObject bindableObject, object newValue, object oldValue) { bindableObject.RiseSelfPropertyChanged(); if (_cashedBindableObject == null) { _cashedBindableObject = bindableObject; } //if UnregisterValue(oldValue); RegisterValue(newValue); }
/// <summary> /// Implement this method to execute your handler processing. /// </summary> /// <param name = "input">Inputs to the current call to the target.</param> /// <param name = "getNext">Delegate to execute to get the next delegate in the handler /// chain.</param> /// <returns> /// Return value from the target. /// </returns> public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { string propertyName; PropertyInfo propertyInfo; object oldValue = null; bool isAttributed = GetAttributedMethodParts(input, out propertyName, out propertyInfo); if (isAttributed && propertyInfo != null) { oldValue = propertyInfo.GetValue(input.Target, null); } // let the original call go through first, so we can notify *after* IMethodReturn result = getNext()(input, getNext); if (!isAttributed) { return(result); } if (propertyInfo != null) { object newValue = propertyInfo.GetValue(input.Target, null); if ((newValue == null || oldValue == null) || !newValue.Equals(oldValue)) { // get the field storing the delegate list that are stored by the event. BindableModelObject bindableModelObject = input.Target as BindableModelObject; if (bindableModelObject != null) { bindableModelObject.RisePropertyChanged(propertyName); } //invoke value changed. if (_containerWiring != null) { _containerWiring.RiseValueChanged(new ValueChangedEventArgs(propertyInfo, input.Target, oldValue, newValue)); } //if } } return(result); }