From 8f353457295767edaaf9dfccb4d938bc1befeb40 Mon Sep 17 00:00:00 2001 From: Berkan Diler Date: Sun, 13 Feb 2022 14:50:07 +0100 Subject: [PATCH] Use Enum and Delegate.CreateDelegate generic overloads (#3111) * Use Enum generic overloads * Remove EnumExtensions.cs * Use Delegate.CreateDelegate generic overloads --- Ryujinx.Common/Extensions/EnumExtensions.cs | 12 ------------ Ryujinx.Common/Logging/Logger.cs | 2 +- Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs | 2 +- Ryujinx.Graphics.OpenGL/FormatTable.cs | 2 +- Ryujinx.Graphics.OpenGL/Queries/Counters.cs | 2 +- Ryujinx.HLE/FileSystem/Content/ContentManager.cs | 2 +- .../HOS/Kernel/SupervisorCall/SyscallTable.cs | 2 +- Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs | 2 +- Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs | 2 +- Ryujinx.Input/Motion/CemuHook/Client.cs | 4 ++-- Ryujinx/Configuration/LoggerModule.cs | 2 +- Ryujinx/Input/GTK3/GTK3MappingHelper.cs | 2 +- Ryujinx/Ui/MainWindow.cs | 2 +- Ryujinx/Ui/Windows/SettingsWindow.cs | 2 +- 14 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 Ryujinx.Common/Extensions/EnumExtensions.cs diff --git a/Ryujinx.Common/Extensions/EnumExtensions.cs b/Ryujinx.Common/Extensions/EnumExtensions.cs deleted file mode 100644 index 560af882..00000000 --- a/Ryujinx.Common/Extensions/EnumExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Ryujinx.Common -{ - public static class EnumExtensions - { - public static T[] GetValues() - { - return (T[])Enum.GetValues(typeof(T)); - } - } -} diff --git a/Ryujinx.Common/Logging/Logger.cs b/Ryujinx.Common/Logging/Logger.cs index e41eaf53..040a555b 100644 --- a/Ryujinx.Common/Logging/Logger.cs +++ b/Ryujinx.Common/Logging/Logger.cs @@ -94,7 +94,7 @@ namespace Ryujinx.Common.Logging static Logger() { - m_EnabledClasses = new bool[Enum.GetNames(typeof(LogClass)).Length]; + m_EnabledClasses = new bool[Enum.GetNames().Length]; for (int index = 0; index < m_EnabledClasses.Length; index++) { diff --git a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs index d281a75a..f8d839fa 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs @@ -112,7 +112,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME _ilGen.Emit(OpCodes.Ret); } - return (MacroExecute)_meth.CreateDelegate(typeof(MacroExecute)); + return _meth.CreateDelegate(); } /// diff --git a/Ryujinx.Graphics.OpenGL/FormatTable.cs b/Ryujinx.Graphics.OpenGL/FormatTable.cs index 41fd9f37..c054ba57 100644 --- a/Ryujinx.Graphics.OpenGL/FormatTable.cs +++ b/Ryujinx.Graphics.OpenGL/FormatTable.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.OpenGL static FormatTable() { - int tableSize = Enum.GetNames(typeof(Format)).Length; + int tableSize = Enum.GetNames().Length; Table = new FormatInfo[tableSize]; TableImage = new SizedInternalFormat[tableSize]; diff --git a/Ryujinx.Graphics.OpenGL/Queries/Counters.cs b/Ryujinx.Graphics.OpenGL/Queries/Counters.cs index 0c0a915d..582800c8 100644 --- a/Ryujinx.Graphics.OpenGL/Queries/Counters.cs +++ b/Ryujinx.Graphics.OpenGL/Queries/Counters.cs @@ -9,7 +9,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries public Counters() { - int count = Enum.GetNames(typeof(CounterType)).Length; + int count = Enum.GetNames().Length; _counterQueues = new CounterQueue[count]; } diff --git a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs index 9203f156..8ac31a4c 100644 --- a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs +++ b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs @@ -102,7 +102,7 @@ namespace Ryujinx.HLE.FileSystem.Content _contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>(); _locationEntries = new Dictionary>(); - foreach (StorageId storageId in Enum.GetValues(typeof(StorageId))) + foreach (StorageId storageId in Enum.GetValues()) { string contentDirectory = null; string contentPathString = null; diff --git a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs index 178dc029..91ab4d96 100644 --- a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs +++ b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SyscallTable.cs @@ -433,7 +433,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall generator.Emit(OpCodes.Ret); - return (Action)method.CreateDelegate(typeof(Action)); + return method.CreateDelegate>(); } private static void CheckIfTypeIsSupported(Type type, string svcName) diff --git a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs index 2fdb94e4..21572b9f 100644 --- a/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs +++ b/Ryujinx.HLE/HOS/Services/Hid/IHidServer.cs @@ -1021,7 +1021,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid HidVibrationDeviceType vibrationDeviceType = HidVibrationDeviceType.None; - if (Enum.IsDefined(typeof(NpadStyleIndex), deviceType)) + if (Enum.IsDefined(deviceType)) { vibrationDeviceType = HidVibrationDeviceType.LinearResonantActuator; } diff --git a/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs b/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs index 8aa0bfff..cceaf563 100644 --- a/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs +++ b/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs @@ -60,7 +60,7 @@ namespace Ryujinx.HLE.HOS.SystemState SystemLanguage.TraditionalChinese => TitleLanguage.Taiwanese, SystemLanguage.Chinese or SystemLanguage.SimplifiedChinese => TitleLanguage.Chinese, - _ => Enum.Parse(Enum.GetName(typeof(SystemLanguage), language)), + _ => Enum.Parse(Enum.GetName(language)), }; } diff --git a/Ryujinx.Input/Motion/CemuHook/Client.cs b/Ryujinx.Input/Motion/CemuHook/Client.cs index 214e23f0..ecaf26f0 100644 --- a/Ryujinx.Input/Motion/CemuHook/Client.cs +++ b/Ryujinx.Input/Motion/CemuHook/Client.cs @@ -27,8 +27,8 @@ namespace Ryujinx.Input.Motion.CemuHook private readonly Dictionary> _motionData; private readonly Dictionary _clients; - private readonly bool[] _clientErrorStatus = new bool[Enum.GetValues(typeof(PlayerIndex)).Length]; - private readonly long[] _clientRetryTimer = new long[Enum.GetValues(typeof(PlayerIndex)).Length]; + private readonly bool[] _clientErrorStatus = new bool[Enum.GetValues().Length]; + private readonly long[] _clientRetryTimer = new long[Enum.GetValues().Length]; private NpadManager _npadManager; public Client(NpadManager npadManager) diff --git a/Ryujinx/Configuration/LoggerModule.cs b/Ryujinx/Configuration/LoggerModule.cs index 44631ea0..2599eeff 100644 --- a/Ryujinx/Configuration/LoggerModule.cs +++ b/Ryujinx/Configuration/LoggerModule.cs @@ -58,7 +58,7 @@ namespace Ryujinx.Configuration { bool noFilter = e.NewValue.Length == 0; - foreach (var logClass in EnumExtensions.GetValues()) + foreach (var logClass in Enum.GetValues()) { Logger.SetEnable(logClass, noFilter); } diff --git a/Ryujinx/Input/GTK3/GTK3MappingHelper.cs b/Ryujinx/Input/GTK3/GTK3MappingHelper.cs index 49ea0d15..1035e415 100644 --- a/Ryujinx/Input/GTK3/GTK3MappingHelper.cs +++ b/Ryujinx/Input/GTK3/GTK3MappingHelper.cs @@ -150,7 +150,7 @@ namespace Ryujinx.Input.GTK3 static GTK3MappingHelper() { - var inputKeys = Enum.GetValues(typeof(Key)); + var inputKeys = Enum.GetValues(); // GtkKey is not contiguous and quite large, so use a dictionary instead of an array. _gtkKeyMapping = new Dictionary(); diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index 6f34304f..cc3c1239 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -1209,7 +1209,7 @@ namespace Ryujinx.Ui { AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value; - ConfigurationState.Instance.Graphics.AspectRatio.Value = ((int)aspectRatio + 1) > Enum.GetNames(typeof(AspectRatio)).Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1; + ConfigurationState.Instance.Graphics.AspectRatio.Value = ((int)aspectRatio + 1) > Enum.GetNames().Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1; } private void Row_Clicked(object sender, ButtonReleaseEventArgs args) diff --git a/Ryujinx/Ui/Windows/SettingsWindow.cs b/Ryujinx/Ui/Windows/SettingsWindow.cs index 0a188fb7..8434d652 100644 --- a/Ryujinx/Ui/Windows/SettingsWindow.cs +++ b/Ryujinx/Ui/Windows/SettingsWindow.cs @@ -181,7 +181,7 @@ namespace Ryujinx.Ui.Windows _fsAccessLogToggle.Click(); } - foreach (GraphicsDebugLevel level in Enum.GetValues(typeof(GraphicsDebugLevel))) + foreach (GraphicsDebugLevel level in Enum.GetValues()) { _graphicsDebugLevel.Append(level.ToString(), level.ToString()); }