Skip to content

Commit

Permalink
fix covariant array conversion can cause runtime exception linq error.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 29, 2021
1 parent 5dfe873 commit 43b7bd1
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -64,22 +65,32 @@ public void ShowWithNoFetch()

Schedule(() =>
{
var columns = colourName.Select(c => new TitleTableColumn(c)).OfType<TableColumn>().ToArray();
var content = providers.Select(provider =>
{
if (provider == null)
throw new ArgumentNullException(nameof(provider));

return colourName.Select(c =>
{
var value = provider.GetType().GetProperty(c)?.GetValue(provider);
if (value == null)
throw new ArgumentNullException(nameof(value));

var colour = (Color4)value;
return new PreviewColourDrawable(colour);
}).OfType<Drawable>();
}).To2DArray();

Child = new OsuScrollContainer(Direction.Horizontal)
{
RelativeSizeAxes = Axes.Both,
Child = new TableContainer
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Columns = colourName.Select(c => new TitleTableColumn(c)).ToArray(),
Content = providers.Select(p =>
{
return colourName.Select(c =>
{
var colour = (Color4)p.GetType().GetProperty(c).GetValue(p);
return new PreviewColourDrawable(colour);
});
}).To2DArray(),
Columns = columns,
Content = content,
}
};
});
Expand Down

0 comments on commit 43b7bd1

Please sign in to comment.