Gate some switch expressions

This commit is contained in:
Matt Nadareski
2023-10-12 01:19:47 -04:00
parent 83437977ba
commit ecee44966e
8 changed files with 318 additions and 51 deletions

View File

@@ -2446,6 +2446,7 @@ namespace MPF.Core.Modules.Aaru
case CommandStrings.ArchivePrefixShort:
case CommandStrings.ArchivePrefixLong:
family = CommandStrings.ArchivePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.ArchiveInfo:
@@ -2455,11 +2456,19 @@ namespace MPF.Core.Modules.Aaru
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.ArchiveInfo => CommandStrings.ArchiveInfo,
_ => null,
};
#endif
break;
case CommandStrings.DatabasePrefixShort:
case CommandStrings.DatabasePrefixLong:
family = CommandStrings.DatabasePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.DatabaseStats:
@@ -2472,12 +2481,21 @@ namespace MPF.Core.Modules.Aaru
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.DatabaseStats => CommandStrings.DatabaseStats,
CommandStrings.DatabaseUpdate => CommandStrings.DatabaseUpdate,
_ => null,
};
#endif
break;
case CommandStrings.DevicePrefixShort:
case CommandStrings.DevicePrefixLong:
family = CommandStrings.DevicePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.DeviceInfo:
@@ -2493,6 +2511,15 @@ namespace MPF.Core.Modules.Aaru
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.DeviceInfo => CommandStrings.DeviceInfo,
CommandStrings.DeviceList => CommandStrings.DeviceList,
CommandStrings.DeviceReport => CommandStrings.DeviceReport,
_ => null,
};
#endif
break;
@@ -2500,6 +2527,7 @@ namespace MPF.Core.Modules.Aaru
case CommandStrings.FilesystemPrefixShortAlt:
case CommandStrings.FilesystemPrefixLong:
family = CommandStrings.FilesystemPrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.FilesystemExtract:
@@ -2519,12 +2547,24 @@ namespace MPF.Core.Modules.Aaru
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.FilesystemExtract => CommandStrings.FilesystemExtract,
CommandStrings.FilesystemInfo => CommandStrings.FilesystemInfo,
CommandStrings.FilesystemListShort => CommandStrings.FilesystemListLong,
CommandStrings.FilesystemListLong => CommandStrings.FilesystemListLong,
CommandStrings.FilesystemOptions => CommandStrings.FilesystemOptions,
_ => null,
};
#endif
break;
case CommandStrings.ImagePrefixShort:
case CommandStrings.ImagePrefixLong:
family = CommandStrings.ImagePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.ImageChecksumShort:
@@ -2563,12 +2603,31 @@ namespace MPF.Core.Modules.Aaru
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.ImageChecksumShort => CommandStrings.ImageChecksumLong,
CommandStrings.ImageChecksumLong => CommandStrings.ImageChecksumLong,
CommandStrings.ImageCompareShort => CommandStrings.ImageCompareLong,
CommandStrings.ImageCompareLong => CommandStrings.ImageCompareLong,
CommandStrings.ImageConvert => CommandStrings.ImageConvert,
CommandStrings.ImageCreateSidecar => CommandStrings.ImageCreateSidecar,
CommandStrings.ImageDecode => CommandStrings.ImageDecode,
CommandStrings.ImageEntropy => CommandStrings.ImageEntropy,
CommandStrings.ImageInfo => CommandStrings.ImageInfo,
CommandStrings.ImageOptions => CommandStrings.ImageOptions,
CommandStrings.ImagePrint => CommandStrings.ImagePrint,
CommandStrings.ImageVerify => CommandStrings.ImageVerify,
_ => null,
};
#endif
break;
case CommandStrings.MediaPrefixShort:
case CommandStrings.MediaPrefixLong:
family = CommandStrings.MediaPrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.MediaDump:
@@ -2584,6 +2643,15 @@ namespace MPF.Core.Modules.Aaru
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.MediaDump => CommandStrings.MediaDump,
CommandStrings.MediaInfo => CommandStrings.MediaInfo,
CommandStrings.MediaScan => CommandStrings.MediaScan,
_ => null,
};
#endif
break;
@@ -2598,6 +2666,7 @@ namespace MPF.Core.Modules.Aaru
else
{
family = null;
#if NET48
switch (splitCommand[0])
{
case CommandStrings.Configure:
@@ -2619,6 +2688,17 @@ namespace MPF.Core.Modules.Aaru
command = null;
break;
}
#else
command = splitCommand[0] switch
{
CommandStrings.Configure => CommandStrings.Configure,
CommandStrings.Formats => CommandStrings.Formats,
CommandStrings.ListEncodings => CommandStrings.ListEncodings,
CommandStrings.ListNamespaces => CommandStrings.ListNamespaces,
CommandStrings.Remote => CommandStrings.Remote,
_ => null,
};
#endif
}
// If the command itself is invalid, then return null

View File

@@ -1951,6 +1951,7 @@ namespace MPF.Core.Modules
/// <returns>Category, if possible</returns>
protected static DiscCategory? GetUMDCategory(string category)
{
#if NET48
switch (category)
{
case "GAME": return DiscCategory.Games;
@@ -1958,6 +1959,15 @@ namespace MPF.Core.Modules
case "AUDIO": return DiscCategory.Audio;
default: return null;
}
#else
return category switch
{
"GAME" => DiscCategory.Games,
"VIDEO" => DiscCategory.Video,
"AUDIO" => DiscCategory.Audio,
_ => null,
};
#endif
}
#endregion
@@ -1989,16 +1999,28 @@ namespace MPF.Core.Modules
{
case 'S':
// Check first two digits of S_PS serial
#if NET48
switch (serial.Substring(5, 2))
{
case "46": return Region.SouthKorea;
case "56": return Region.SouthKorea;
case "51": return Region.Asia;
case "56": return Region.SouthKorea;
case "55": return Region.Asia;
default: return Region.Japan;
}
#else
return serial.Substring(5, 2) switch
{
"46" => Region.SouthKorea,
"51" => Region.Asia,
"56" => Region.SouthKorea,
"55" => Region.Asia,
_ => Region.Japan,
};
#endif
case 'M':
// Check first three digits of S_PM serial
#if NET48
switch (serial.Substring(5, 3))
{
case "645": return Region.SouthKorea;
@@ -2006,6 +2028,15 @@ namespace MPF.Core.Modules
case "885": return Region.SouthKorea;
default: return Region.Japan; // Remaining S_PM serials may be Japan or Asia
}
#else
return serial.Substring(5, 3) switch
{
"645" => Region.SouthKorea,
"675" => Region.SouthKorea,
"885" => Region.SouthKorea,
_ => Region.Japan, // Remaining S_PM serials may be Japan or Asia
};
#endif
default: return Region.Japan;
}
}

View File

@@ -1991,6 +1991,7 @@ namespace MPF.Core.Modules.DiscImageCreator
/// <inheritdoc/>
public override bool IsDumpingCommand()
{
#if NET48
switch (BaseCommand)
{
case CommandStrings.Audio:
@@ -2013,6 +2014,27 @@ namespace MPF.Core.Modules.DiscImageCreator
default:
return false;
}
#else
return BaseCommand switch
{
CommandStrings.Audio
or CommandStrings.BluRay
or CommandStrings.CompactDisc
or CommandStrings.Data
or CommandStrings.DigitalVideoDisc
or CommandStrings.Disk
or CommandStrings.Floppy
or CommandStrings.GDROM
or CommandStrings.SACD
or CommandStrings.Swap
or CommandStrings.Tape
or CommandStrings.XBOX
or CommandStrings.XBOXSwap
or CommandStrings.XGD2Swap
or CommandStrings.XGD3Swap => true,
_ => false,
};
#endif
}
/// <inheritdoc/>
@@ -2061,6 +2083,7 @@ namespace MPF.Core.Modules.DiscImageCreator
this[FlagStrings.DisableBeep] = true;
// Set the C2 reread count
#if NET48
switch (options.DICRereadCount)
{
case -1:
@@ -2073,8 +2096,17 @@ namespace MPF.Core.Modules.DiscImageCreator
C2OpcodeValue[0] = options.DICRereadCount;
break;
}
#else
C2OpcodeValue[0] = options.DICRereadCount switch
{
-1 => null,
0 => 20,
_ => options.DICRereadCount,
};
#endif
// Set the DVD/HD-DVD/BD reread count
#if NET48
switch (options.DICDVDRereadCount)
{
case -1:
@@ -2087,6 +2119,14 @@ namespace MPF.Core.Modules.DiscImageCreator
DVDRereadValue = options.DICDVDRereadCount;
break;
}
#else
DVDRereadValue = options.DICDVDRereadCount switch
{
-1 => null,
0 => 10,
_ => options.DICDVDRereadCount,
};
#endif
// Now sort based on disc type
switch (this.Type)
@@ -3850,6 +3890,7 @@ namespace MPF.Core.Modules.DiscImageCreator
#endif
string month = dateSplit[1];
#if NET48
switch (month)
{
case "JAN":
@@ -3892,6 +3933,24 @@ namespace MPF.Core.Modules.DiscImageCreator
dateSplit[1] = "00";
break;
}
#else
dateSplit[1] = month switch
{
"JAN" => "01",
"FEB" => "02",
"MAR" => "03",
"APR" => "04",
"MAY" => "05",
"JUN" => "06",
"JUL" => "07",
"AUG" => "08",
"SEP" => "09",
"OCT" => "10",
"NOV" => "11",
"DEC" => "12",
_ => "00",
};
#endif
date = string.Join("-", dateSplit);

View File

@@ -1030,6 +1030,7 @@ namespace MPF.Core.Modules.Redumper
switch (this.Type)
{
case MediaType.CDROM:
#if NET48
switch (this.System)
{
case RedumpSystem.SuperAudioCD:
@@ -1039,6 +1040,13 @@ namespace MPF.Core.Modules.Redumper
ModeValues = new List<string> { CommandStrings.CD };
break;
}
#else
ModeValues = this.System switch
{
RedumpSystem.SuperAudioCD => new List<string> { CommandStrings.SACD },
_ => new List<string> { CommandStrings.CD },
};
#endif
break;
case MediaType.DVD:
ModeValues = new List<string> { CommandStrings.DVD };
@@ -1343,7 +1351,7 @@ namespace MPF.Core.Modules.Redumper
return true;
}
#endregion
#endregion
#region Information Extraction Methods