internal static void AssertBindingExists <TDest, TParam>( BindableObject bindable, BindableProperty targetProperty, IList <BindingBase> bindings, IMultiValueConverter?converter = null, TParam?converterParameter = default, BindingMode mode = BindingMode.Default, bool assertConverterInstanceIsAnyNotNull = false, string?stringFormat = null, TDest?targetNullValue = default, TDest?fallbackValue = default, Action <IMultiValueConverter>?assertConvert = null) { var binding = GetMultiBinding(bindable, targetProperty) ?? throw new NullReferenceException(); Assert.That(binding, Is.Not.Null); Assert.That(binding.Bindings.SequenceEqual(bindings), Is.True); Assert.That(binding.Mode, Is.EqualTo(mode)); if (assertConverterInstanceIsAnyNotNull) { Assert.That(binding.Converter, Is.Not.Null); } else { Assert.That(binding.Converter, Is.EqualTo(converter)); } Assert.That(binding.ConverterParameter, Is.EqualTo(converterParameter)); Assert.That(binding.StringFormat, Is.EqualTo(stringFormat)); Assert.That(binding.TargetNullValue, Is.EqualTo(targetNullValue)); Assert.That(binding.FallbackValue, Is.EqualTo(fallbackValue)); assertConvert?.Invoke(binding.Converter); }
/// <summary>Bind to a specified property with 4 bindings, an inline convertor and a converter parameter</summary> public static TBindable Bind <TBindable, TSource1, TSource2, TSource3, TSource4, TParam, TDest>( this TBindable bindable, BindableProperty targetProperty, BindingBase binding1, BindingBase binding2, BindingBase binding3, BindingBase binding4, Func <ValueTuple <TSource1?, TSource2?, TSource3?, TSource4?>, TParam?, TDest>?convert = null, Func <TDest?, TParam?, ValueTuple <TSource1, TSource2, TSource3, TSource4> >?convertBack = null, TParam?converterParameter = default, BindingMode mode = BindingMode.Default, string?stringFormat = null, TDest?targetNullValue = default, TDest?fallbackValue = default) where TBindable : BindableObject => bindable.Bind( targetProperty, new List <BindingBase> { binding1, binding2, binding3, binding4 }, new FuncMultiConverterWithParam <TSource1, TSource2, TSource3, TSource4, TDest, TParam>(convert, convertBack), converterParameter, mode, stringFormat, targetNullValue, fallbackValue);
internal static void AssertBindingExists <TDest, TParam>( BindableObject bindable, BindableProperty targetProperty, string path = ".", BindingMode mode = BindingMode.Default, bool assertConverterInstanceIsAnyNotNull = false, IValueConverter?converter = null, TParam?converterParameter = default, string?stringFormat = null, object?source = null, TDest?targetNullValue = default, TDest?fallbackValue = default, Action <IValueConverter>?assertConvert = null) { var binding = GetBinding(bindable, targetProperty) ?? throw new NullReferenceException(); Assert.That(binding, Is.Not.Null); Assert.That(binding.Path, Is.EqualTo(path)); Assert.That(binding.Mode, Is.EqualTo(mode)); if (assertConverterInstanceIsAnyNotNull) { Assert.That(binding.Converter, Is.Not.Null); } else { Assert.That(binding.Converter, Is.EqualTo(converter)); } Assert.That(binding.ConverterParameter, Is.EqualTo(converterParameter)); Assert.That(binding.StringFormat, Is.EqualTo(stringFormat)); Assert.That(binding.Source, Is.EqualTo(source)); Assert.That(binding.TargetNullValue, Is.EqualTo(targetNullValue)); Assert.That(binding.FallbackValue, Is.EqualTo(fallbackValue)); assertConvert?.Invoke(binding.Converter); }
public TDest Map <TSrc, TDest>(TSrc src, TDest?dest = null) where TDest : class { if (dest == null) { return(_mapper.Map <TSrc, TDest>(src)); } return(_mapper.Map(src, dest)); }
internal static void AssertBindingExists <TDest>( BindableObject bindable, BindableProperty targetProperty, IList <BindingBase> bindings, IMultiValueConverter?converter = null, BindingMode mode = BindingMode.Default, bool assertConverterInstanceIsAnyNotNull = false, string?stringFormat = null, TDest?targetNullValue = default, TDest?fallbackValue = default, Action <IMultiValueConverter>?assertConvert = null) => AssertBindingExists <TDest, object>( bindable, targetProperty, bindings, converter, null, mode, assertConverterInstanceIsAnyNotNull, stringFormat, targetNullValue, fallbackValue, assertConvert);
internal static void AssertBindingExists <TDest>( BindableObject bindable, BindableProperty targetProperty, string path = ".", BindingMode mode = BindingMode.Default, bool assertConverterInstanceIsAnyNotNull = false, IValueConverter?converter = null, string?stringFormat = null, object?source = null, TDest?targetNullValue = default, TDest?fallbackValue = default, Action <IValueConverter>?assertConvert = null) => AssertBindingExists <TDest, object>( bindable, targetProperty, path, mode, assertConverterInstanceIsAnyNotNull, converter, null, stringFormat, source, targetNullValue, fallbackValue, assertConvert);
/// <summary>Bind to the default property with inline conversion</summary> public static TBindable Bind <TBindable, TSource, TDest>( this TBindable bindable, string path = bindingContextPath, BindingMode mode = BindingMode.Default, Func <TSource?, TDest>?convert = null, Func <TDest?, TSource>?convertBack = null, string?stringFormat = null, object?source = null, TDest?targetNullValue = default, TDest?fallbackValue = default) where TBindable : BindableObject { var converter = new FuncConverter <TSource, TDest, object>(convert, convertBack); bindable.Bind( DefaultBindableProperties.GetFor(bindable), path, mode, converter, null, stringFormat, source, targetNullValue, fallbackValue); return(bindable); }
/// <summary>Bind to a specified property with 2 bindings and an inline convertor</summary> public static TBindable Bind <TBindable, TSource1, TSource2, TDest>( this TBindable bindable, BindableProperty targetProperty, BindingBase binding1, BindingBase binding2, Func <ValueTuple <TSource1?, TSource2?>, TDest>?convert = null, Func <TDest?, ValueTuple <TSource1, TSource2> >?convertBack = null, BindingMode mode = BindingMode.Default, string?stringFormat = null, TDest?targetNullValue = default, TDest?fallbackValue = default) where TBindable : BindableObject => bindable.Bind( targetProperty, new List <BindingBase> { binding1, binding2 }, new FuncMultiConverter <TSource1, TSource2, TDest>(convert, convertBack), null, mode, stringFormat, targetNullValue, fallbackValue);
/// <summary>Bind to a specified property with inline conversion and conversion parameter</summary> public static TBindable Bind <TBindable, TSource, TParam, TDest>( this TBindable bindable, BindableProperty targetProperty, string path = bindingContextPath, BindingMode mode = BindingMode.Default, Func <TSource?, TParam?, TDest>?convert = null, Func <TDest?, TParam?, TSource>?convertBack = null, TParam?converterParameter = default, string?stringFormat = null, object?source = null, TDest?targetNullValue = default, TDest?fallbackValue = default) where TBindable : BindableObject { var converter = new FuncConverter <TSource, TDest, TParam>(convert, convertBack); bindable.SetBinding( targetProperty, new Binding(path, mode, converter, converterParameter, stringFormat, source) { TargetNullValue = targetNullValue, FallbackValue = fallbackValue }); return(bindable); }
public TDest Map <TSrc, TDest>(TSrc src, TDest?dest = null) where TDest : class #pragma warning disable CS8603 // Possible null reference return. => dest;
public abstract TSource?ConvertBack(TDest?value, Type targetType, TParam?parameter, CultureInfo culture);