From 43b7bd1a2dc42af40f6a336261a285458b5a15c9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 29 Aug 2021 19:44:54 +0900 Subject: [PATCH] fix covariant array conversion can cause runtime exception linq error. --- .../TestSceneOverlayColourProvider.cs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs b/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs index 9cb13ece1..5424b29e1 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs @@ -1,6 +1,7 @@ // Copyright (c) andy840119 . 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; @@ -64,6 +65,23 @@ public void ShowWithNoFetch() Schedule(() => { + var columns = colourName.Select(c => new TitleTableColumn(c)).OfType().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(); + }).To2DArray(); + Child = new OsuScrollContainer(Direction.Horizontal) { RelativeSizeAxes = Axes.Both, @@ -71,15 +89,8 @@ public void ShowWithNoFetch() { 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, } }; });