From 0315ee1223a2ad463fa045bffa41777e4a5e7b8e Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Sun, 22 Dec 2024 16:23:35 -0300 Subject: [PATCH] Prefer generic overload when type is known (#430) --- src/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs | 2 +- src/Ryujinx.Graphics.Vulkan/FormatTable.cs | 2 +- src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs | 2 +- src/Ryujinx.HLE/HOS/Services/IpcService.cs | 12 ++++++------ .../IUserLocalCommunicationService.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs | 2 +- src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs | 4 ++-- src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs b/src/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs index 4971a63b6c..09f22889c4 100644 --- a/src/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs +++ b/src/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs @@ -62,7 +62,7 @@ public FormatCapabilities(Vk api, PhysicalDevice physicalDevice) _api = api; _physicalDevice = physicalDevice; - int totalFormats = Enum.GetNames(typeof(Format)).Length; + int totalFormats = Enum.GetNames().Length; _bufferTable = new FormatFeatureFlags[totalFormats]; _optimalTable = new FormatFeatureFlags[totalFormats]; diff --git a/src/Ryujinx.Graphics.Vulkan/FormatTable.cs b/src/Ryujinx.Graphics.Vulkan/FormatTable.cs index 98796d9bf8..305224cad8 100644 --- a/src/Ryujinx.Graphics.Vulkan/FormatTable.cs +++ b/src/Ryujinx.Graphics.Vulkan/FormatTable.cs @@ -12,7 +12,7 @@ static class FormatTable static FormatTable() { - _table = new VkFormat[Enum.GetNames(typeof(Format)).Length]; + _table = new VkFormat[Enum.GetNames().Length]; _reverseMap = new Dictionary(); #pragma warning disable IDE0055 // Disable formatting diff --git a/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs b/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs index 518ede5f32..c07e1c09cc 100644 --- a/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs +++ b/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs @@ -13,7 +13,7 @@ public Counters(VulkanRenderer gd, Device device, PipelineFull pipeline) { _pipeline = pipeline; - int count = Enum.GetNames(typeof(CounterType)).Length; + int count = Enum.GetNames().Length; _counterQueues = new CounterQueue[count]; diff --git a/src/Ryujinx.HLE/HOS/Services/IpcService.cs b/src/Ryujinx.HLE/HOS/Services/IpcService.cs index 808f21c0eb..cd3df4edfb 100644 --- a/src/Ryujinx.HLE/HOS/Services/IpcService.cs +++ b/src/Ryujinx.HLE/HOS/Services/IpcService.cs @@ -23,18 +23,18 @@ abstract class IpcService public IpcService(ServerBase server = null) { - CmifCommands = typeof(IpcService).Assembly.GetTypes() + CmifCommands = GetType().Assembly.GetTypes() .Where(type => type == GetType()) .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)) - .SelectMany(methodInfo => methodInfo.GetCustomAttributes(typeof(CommandCmifAttribute)) - .Select(command => (((CommandCmifAttribute)command).Id, methodInfo))) + .SelectMany(methodInfo => methodInfo.GetCustomAttributes() + .Select(command => (command.Id, methodInfo))) .ToDictionary(command => command.Id, command => command.methodInfo); - TipcCommands = typeof(IpcService).Assembly.GetTypes() + TipcCommands = GetType().Assembly.GetTypes() .Where(type => type == GetType()) .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)) - .SelectMany(methodInfo => methodInfo.GetCustomAttributes(typeof(CommandTipcAttribute)) - .Select(command => (((CommandTipcAttribute)command).Id, methodInfo))) + .SelectMany(methodInfo => methodInfo.GetCustomAttributes() + .Select(command => (command.Id, methodInfo))) .ToDictionary(command => command.Id, command => command.methodInfo); Server = server; diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs index 9f65aed4b8..b8b3014f1c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs @@ -444,7 +444,7 @@ private ResultCode ScanImpl(ServiceCtx context, bool isPrivate = false) private ResultCode ScanInternal(IVirtualMemoryManager memory, ushort channel, ScanFilter scanFilter, ulong bufferPosition, ulong bufferSize, out ulong counter) { - ulong networkInfoSize = (ulong)Marshal.SizeOf(typeof(NetworkInfo)); + ulong networkInfoSize = (ulong)Marshal.SizeOf(); ulong maxGames = bufferSize / networkInfoSize; MemoryHelper.FillWithZeros(memory, bufferPosition, (int)bufferSize); diff --git a/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs b/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs index 7a90c664e3..271b8fc84a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs @@ -94,7 +94,7 @@ public ResultCode GetService(ServiceCtx context) { if (_services.TryGetValue(name, out Type type)) { - ServiceAttribute serviceAttribute = (ServiceAttribute)type.GetCustomAttributes(typeof(ServiceAttribute)).First(service => ((ServiceAttribute)service).Name == name); + ServiceAttribute serviceAttribute = type.GetCustomAttributes().First(service => service.Name == name); IpcService service = GetServiceInstance(type, context, serviceAttribute.Parameter); diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index f11d6e4049..493e6659db 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -97,7 +97,7 @@ public PlayerIndex PlayerId { if (IsModified) { - + _playerIdChoose = value; return; } @@ -105,7 +105,7 @@ public PlayerIndex PlayerId IsModified = false; _playerId = value; - if (!Enum.IsDefined(typeof(PlayerIndex), _playerId)) + if (!Enum.IsDefined(_playerId)) { _playerId = PlayerIndex.Player1; diff --git a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs index dd4ed82973..1b017dbeb1 100644 --- a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs @@ -52,7 +52,7 @@ private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArg private void AspectRatioStatus_OnClick(object sender, RoutedEventArgs e) { 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 Refresh_OnClick(object sender, RoutedEventArgs e) => Window.LoadApplications();