private object GetTargetValue(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError) { object value = GetRawValueInternal(targetMember, context, throwOnError); if (value.IsUnsetValueOrDoNothing()) { return(value); } if (_parameters.ConverterDelegate != null) { IBindingValueConverter converter = _parameters.ConverterDelegate(context); if (converter != null) { CultureInfo culture = _parameters.ConverterCultureDelegate.GetValueOrDefault(context, BindingServiceProvider.BindingCultureInfo()); object parameter = _parameters.ConverterParameterDelegate.GetValueOrDefault(context); value = converter.ConvertBack(value, targetMember.Type, parameter, culture, context); } } if (Equals(value, _parameters.TargetNullValue)) { return(null); } return(value); }
private object GetSourceValue(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError) { var isDebuggable = IsDebuggable; object value = GetRawValueInternal(targetMember, context, throwOnError); if (isDebuggable) { DebugInfo($"Got a source value: '{value}'"); } if (value.IsDoNothing()) { return(BindingConstants.DoNothing); } if (_parameters.ConverterDelegate != null && !value.IsUnsetValue()) { IBindingValueConverter converter = _parameters.ConverterDelegate(context); if (converter != null) { CultureInfo culture = _parameters.ConverterCultureDelegate?.Invoke(context) ?? BindingServiceProvider.BindingCultureInfo(); object parameter = _parameters.ConverterParameterDelegate?.Invoke(context); if (isDebuggable) { DebugInfo($"Applying converter for source value: '{value}', converter: '{converter}', parameter: '{parameter}', culture: {culture}, target type: '{targetMember.Type}'"); value = converter.Convert(value, targetMember.Type, parameter, culture, context); DebugInfo($"Converter '{converter}' returns value: '{value}'"); } else { value = converter.Convert(value, targetMember.Type, parameter, culture, context); } } } if (value.IsUnsetValue()) { value = _parameters.FallbackDelegate?.Invoke(context) ?? targetMember.Type.GetDefaultValue(); } if (value == null) { return(_parameters.TargetNullValue); } return(value); }