Added a constructor to FuncMultiValueConverter that takes an IReadOnlyList instead of an IEnumerable (#19936)
Co-authored-by: Max Katz <maxkatz6@outlook.com>
This commit is contained in:
committed by
GitHub
parent
80223ca7d4
commit
538a4b2993
@@ -13,15 +13,24 @@ namespace Avalonia.Data.Converters
|
||||
/// <typeparam name="TOut">The output type.</typeparam>
|
||||
public class FuncMultiValueConverter<TIn, TOut> : IMultiValueConverter
|
||||
{
|
||||
private readonly Func<IEnumerable<TIn?>, TOut> _convert;
|
||||
private readonly Func<IReadOnlyList<TIn?>, TOut> _convert;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FuncValueConverter{TIn, TOut}"/> class.
|
||||
/// Initializes a new instance of the <see cref="FuncMultiValueConverter{TIn, TOut}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="convert">The convert function.</param>
|
||||
public FuncMultiValueConverter(Func<IReadOnlyList<TIn?>, TOut> convert)
|
||||
{
|
||||
_convert = convert;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FuncMultiValueConverter{TIn, TOut}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="convert">The convert function.</param>
|
||||
public FuncMultiValueConverter(Func<IEnumerable<TIn?>, TOut> convert)
|
||||
: this(new Func<IReadOnlyList<TIn?>, TOut>(convert))
|
||||
{
|
||||
_convert = convert;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -153,6 +153,20 @@ namespace Avalonia.Base.UnitTests
|
||||
|
||||
Assert.Equal(",Bar,Baz", value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MultiValueConverter_Supports_Indexing_The_Parameters()
|
||||
{
|
||||
var target = new FuncMultiValueConverter<string, string>(v => v[0]);
|
||||
|
||||
object value = target.Convert(new[] { "Foo", "Bar", "Baz" }, typeof(string), null, CultureInfo.InvariantCulture);
|
||||
|
||||
Assert.Equal("Foo", value);
|
||||
|
||||
value = target.Convert(new[] { null, "Bar", "Baz" }, typeof(string), null, CultureInfo.InvariantCulture);
|
||||
|
||||
Assert.Null(value);
|
||||
}
|
||||
|
||||
private struct StringValueTypeWrapper
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user