Use switch with type matching in place of if-else where possible

This commit is contained in:
Dean Herbert
2018-07-17 14:35:09 +09:00
parent b69f61886c
commit 825941aff1
12 changed files with 150 additions and 131 deletions

View File

@ -73,12 +73,17 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
downloader.Download();
};
downloader.DownloadState.ValueChanged += d =>
downloader.DownloadState.ValueChanged += state =>
{
if (d == BeatmapSetDownloader.DownloadStatus.Downloaded)
this.FadeOut(200);
else if (d == BeatmapSetDownloader.DownloadStatus.NotDownloaded)
this.FadeIn(200);
switch (state)
{
case BeatmapSetDownloader.DownloadStatus.Downloaded:
this.FadeOut(200);
break;
case BeatmapSetDownloader.DownloadStatus.NotDownloaded:
this.FadeIn(200);
break;
}
};
}
}

View File

@ -188,16 +188,17 @@ namespace osu.Game.Overlays
int optionCount = 0;
int selectedOption = -1;
if (description.RawValue is bool)
switch (description.RawValue)
{
optionCount = 1;
if ((bool)description.RawValue) selectedOption = 0;
}
else if (description.RawValue is Enum)
{
var values = Enum.GetValues(description.RawValue.GetType());
optionCount = values.Length;
selectedOption = Convert.ToInt32(description.RawValue);
case bool val:
optionCount = 1;
if (val) selectedOption = 0;
break;
case Enum _:
var values = Enum.GetValues(description.RawValue.GetType());
optionCount = values.Length;
selectedOption = Convert.ToInt32(description.RawValue);
break;
}
textLine2.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre;