private void synchronize(INotifyPropertyChanged sourceObject, string sourceProperty, INotifyPropertyChanged targetObject, string targetProperty) { PropertyInfo targetPropertyInfo = resolvePropertyInfo(targetObject, targetProperty); PropertyInfo sourcePropertyInfo = resolvePropertyInfo(sourceObject, sourceProperty); if (sourcePropertyInfo != null && targetPropertyInfo != null && targetPropertyInfo.CanWrite) { object bValue = sourcePropertyInfo.GetValue(sourceObject, null); if (converter != null && bValue != null) { bValue = converter.convert(bValue); } try { if (validator == null || validator.validate(bValue)) { targetPropertyInfo.SetValue(targetObject, bValue, null); } } catch (Exception e) { throw new MemberAccessException("Could not set property '" + targetProperty + "' to '" + bValue + "' [" + ((bValue != null) ? bValue.GetType().Name : "") + "] on " + targetObject + ". Probably other type than expected, IBindingCoverter to the rescue.", e); } } }
private void Synchronize(INotifyPropertyChanged sourceObject, string sourceProperty, INotifyPropertyChanged targetObject, string targetProperty) { var targetPropertyInfo = ResolvePropertyInfo(targetObject, targetProperty); var sourcePropertyInfo = ResolvePropertyInfo(sourceObject, sourceProperty); if (sourcePropertyInfo == null || targetPropertyInfo == null || !targetPropertyInfo.CanWrite) { return; } var bValue = sourcePropertyInfo.GetValue(sourceObject, null); if (Converter != null && bValue != null) { bValue = Converter.Convert(bValue); } try { if (_validator == null || _validator.validate(bValue)) { targetPropertyInfo.SetValue(targetObject, bValue, null); } } catch (Exception e) { throw new MemberAccessException( "Could not set property '" + targetProperty + "' to '" + bValue + "' [" + (bValue?.GetType().Name ?? "") + "] on " + targetObject + ". Probably other type than expected, IBindingCoverter to the rescue.", e); } }