From bcf5347823d78b59a36693fbcf3194feae80108b Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 28 Dec 2020 00:07:06 +1000 Subject: [PATCH] Use C# 9 improvements to switch / "pattern matching" --- .../lua/LuaHelperLibs/NESLuaLibrary.cs | 2 +- .../Extensions/CoreExtensions.cs | 16 ++++++++-------- .../GraphicsImplementations/IGLExtensions.cs | 6 +++--- src/BizHawk.Client.EmuHawk/MainForm.cs | 14 +++++++------- .../tools/ExternalToolManager.cs | 6 +++--- .../tools/VirtualPads/VirtualpadsTool.cs | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs index 72db4ddbff..03b4367ed7 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs @@ -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() }; diff --git a/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs index 501b72b35b..7c9e134cb7 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs @@ -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 }; } diff --git a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGLExtensions.cs b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGLExtensions.cs index fa0cf7aff6..a3a058a68b 100644 --- a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGLExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGLExtensions.cs @@ -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() }; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 52a34fda9a..df065df4d5 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -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 }; } diff --git a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs index 2397e3d090..1ee41b185f 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs @@ -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}" }; } diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs index d69551433b..57cfe122ec 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs @@ -99,8 +99,8 @@ namespace BizHawk.Client.EmuHawk { Predicate 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))