Browse Source

Merge pull request #12160 from Enscape/feature/untyped-property-observable-converter

Support non-generic `AvaloniaProperty` in `GetObservable(converter)`
pull/12261/head
Max Katz 3 years ago
committed by GitHub
parent
commit
06afe81e7f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/Avalonia.Base/AvaloniaObjectExtensions.cs

20
src/Avalonia.Base/AvaloniaObjectExtensions.cs

@ -60,6 +60,8 @@ namespace Avalonia
}
/// <inheritdoc cref="GetObservable{T}(AvaloniaObject, AvaloniaProperty{T})"/>
/// <typeparam name="TSource">The type of the values held by the <paramref name="property"/>.</typeparam>
/// <typeparam name="TResult">The type of the value returned by the <paramref name="converter"/>.</typeparam>
/// <param name="o"/>
/// <param name="property"/>
/// <param name="converter">A method which is executed to convert each property value to <typeparamref name="TResult"/>.</param>
@ -71,6 +73,15 @@ namespace Avalonia
converter ?? throw new ArgumentNullException(nameof(converter)));
}
/// <inheritdoc cref="GetObservable{TSource,TResult}"/>
public static IObservable<TResult> GetObservable<TResult>(this AvaloniaObject o, AvaloniaProperty property, Func<object?, TResult> converter)
{
return new AvaloniaPropertyObservable<object?, TResult>(
o ?? throw new ArgumentNullException(nameof(o)),
property ?? throw new ArgumentNullException(nameof(property)),
converter ?? throw new ArgumentNullException(nameof(converter)));
}
/// <summary>
/// Gets an observable for an <see cref="AvaloniaProperty"/>.
/// </summary>
@ -92,6 +103,15 @@ namespace Avalonia
property ?? throw new ArgumentNullException(nameof(property)));
}
/// <inheritdoc cref="GetObservable{TSource,TResult}"/>
public static IObservable<BindingValue<TResult>> GetBindingObservable<TResult>(this AvaloniaObject o, AvaloniaProperty property, Func<object?, TResult> converter)
{
return new AvaloniaPropertyBindingObservable<object?, TResult>(
o ?? throw new ArgumentNullException(nameof(o)),
property ?? throw new ArgumentNullException(nameof(property)),
converter?? throw new ArgumentNullException(nameof(converter)));
}
/// <summary>
/// Gets an observable for an <see cref="AvaloniaProperty"/>.
/// </summary>

Loading…
Cancel
Save