Use C# 9 improvements to switch / "pattern matching"

This commit is contained in:
YoshiRulz 2020-12-28 00:07:06 +10:00
parent 96f9e8f6e4
commit bcf5347823
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
6 changed files with 24 additions and 24 deletions

View File

@ -66,7 +66,7 @@ namespace BizHawk.Client.Common
public bool GetDisplayBackground() => Settings switch
{
NES.NESSettings nhs => nhs.DispBackground,
QuickNES.QuickNESSettings _ => true,
QuickNES.QuickNESSettings => true,
_ => throw new InvalidOperationException()
};

View File

@ -27,14 +27,14 @@ namespace BizHawk.Client.EmuHawk.CoreExtensions
return core switch
{
QuickNES _ => Properties.Resources.QuickNes,
LibsnesCore _ => Properties.Resources.Bsnes,
GPGX _ => Properties.Resources.GenPlus,
Gameboy _ => Properties.Resources.Gambatte,
Snes9x _ => Properties.Resources.Snes9X,
MAME _ => Properties.Resources.Mame,
MGBAHawk _ => Properties.Resources.Mgba,
MelonDS _ => Properties.Resources.MelonDS,
QuickNES => Properties.Resources.QuickNes,
LibsnesCore => Properties.Resources.Bsnes,
GPGX => Properties.Resources.GenPlus,
Gameboy => Properties.Resources.Gambatte,
Snes9x => Properties.Resources.Snes9X,
MAME => Properties.Resources.Mame,
MGBAHawk => Properties.Resources.Mgba,
MelonDS => Properties.Resources.MelonDS,
_ => null
};
}

View File

@ -9,9 +9,9 @@ namespace BizHawk.Client.EmuHawk
{
public static IGuiRenderer CreateRenderer(this IGL gl) => gl switch
{
IGL_GdiPlus _ => (IGuiRenderer) new GDIPlusGuiRenderer(gl),
IGL_SlimDX9 _ => new GuiRenderer(gl),
IGL_TK _ => new GuiRenderer(gl),
IGL_GdiPlus => new GDIPlusGuiRenderer(gl),
IGL_SlimDX9 => new GuiRenderer(gl),
IGL_TK => new GuiRenderer(gl),
_ => throw new NotSupportedException()
};
}

View File

@ -419,10 +419,10 @@ namespace BizHawk.Client.EmuHawk
? Input.AllowInput.OnlyController
: Input.AllowInput.All
: Input.AllowInput.None,
TAStudio _ when yieldAlt => Input.AllowInput.None,
FormBase f when !f.BlocksInputWhenFocused => Input.AllowInput.All,
ControllerConfig _ => Input.AllowInput.All,
HotkeyConfig _ => Input.AllowInput.All,
TAStudio when yieldAlt => Input.AllowInput.None,
FormBase { BlocksInputWhenFocused: false } => Input.AllowInput.All,
ControllerConfig => Input.AllowInput.All,
HotkeyConfig => Input.AllowInput.All,
_ => Input.AllowInput.None
}
);
@ -4220,9 +4220,9 @@ namespace BizHawk.Client.EmuHawk
return Emulator switch
{
Snes9x _ => PromptToSwitchCore(CoreNames.Snes9X, CoreNames.Bsnes, () => Config.PreferredCores["SNES"] = CoreNames.Bsnes),
QuickNES _ => PromptToSwitchCore(CoreNames.QuickNes, CoreNames.NesHawk, () => Config.PreferredCores["NES"] = CoreNames.NesHawk),
HyperNyma _ => PromptToSwitchCore(CoreNames.HyperNyma, CoreNames.TurboNyma, () => Config.PreferredCores["PCE"] = CoreNames.TurboNyma),
Snes9x => PromptToSwitchCore(CoreNames.Snes9X, CoreNames.Bsnes, () => Config.PreferredCores["SNES"] = CoreNames.Bsnes),
QuickNES => PromptToSwitchCore(CoreNames.QuickNes, CoreNames.NesHawk, () => Config.PreferredCores["NES"] = CoreNames.NesHawk),
HyperNyma => PromptToSwitchCore(CoreNames.HyperNyma, CoreNames.TurboNyma, () => Config.PreferredCores["PCE"] = CoreNames.TurboNyma),
_ => true
};
}

View File

@ -126,12 +126,12 @@ namespace BizHawk.Client.EmuHawk
#endif
item.ToolTipText = e switch
{
BadImageFormatException _ => "This assembly can't be loaded, probably because it's corrupt or targets an incompatible .NET runtime.",
ExternalToolApplicabilityAttributeBase.DuplicateException _ => "The IExternalToolForm has conflicting applicability attributes.",
BadImageFormatException => "This assembly can't be loaded, probably because it's corrupt or targets an incompatible .NET runtime.",
ExternalToolApplicabilityAttributeBase.DuplicateException => "The IExternalToolForm has conflicting applicability attributes.",
ExternalToolAttribute.MissingException e1 => e1.OldAttributeFound
? "The assembly doesn't contain a class implementing IExternalToolForm and annotated with [ExternalTool].\nHowever, the assembly itself is annotated with [BizHawkExternalTool], which is now deprecated. Has the tool been updated since BizHawk 2.4?"
: "The assembly doesn't contain a class implementing IExternalToolForm and annotated with [ExternalTool].",
ReflectionTypeLoadException _ => "Something went wrong while trying to load the assembly.",
ReflectionTypeLoadException => "Something went wrong while trying to load the assembly.",
_ => $"An exception of type {e.GetType().FullName} was thrown while trying to load the assembly and look for an IExternalToolForm:\n{e.Message}"
};
}

View File

@ -99,8 +99,8 @@ namespace BizHawk.Client.EmuHawk
{
Predicate<string> searchSetContains = controlSchema switch
{
ButtonSchema _ => buttonControls.Contains,
DiscManagerSchema _ => s => buttonControls.Contains(s) || axisControls.ContainsKey(s),
ButtonSchema => buttonControls.Contains,
DiscManagerSchema => s => buttonControls.Contains(s) || axisControls.ContainsKey(s),
_ => axisControls.ContainsKey
};
if (!searchSetContains(controlSchema.Name))