Applied some C#12 stuff

This commit is contained in:
DarthAffe committed 2023-12-22 20:56:56 +01:00
1 parent 0444730aca
commit d85f1559b3
105 files changed
+329 -422

No files matched your search

@@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Represents a logitech RGB-device.
/// </summary>
public interface ILogitechRGBDevice : IRGBDevice
{ }
public interface ILogitechRGBDevice : IRGBDevice;
@@ -23,20 +23,20 @@ public sealed class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefi
private const int VENDOR_ID = 0x046D;
// ReSharper disable once StaticMemberInGenericType - This is used like a const
private static readonly List<int> RECEIVER_PIDS = new()
{
0xC539,
0xC53A,
0xC541,
0xC545,
0xC547
};
private static readonly List<int> RECEIVER_PIDS =
[
0xC539,
0xC53A,
0xC541,
0xC545,
0xC547
];
#endregion
#region Properties & Fields
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new();
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = [];
/// <summary>
/// Gets the vendor id used for this loader.
@@ -117,7 +117,7 @@ public sealed class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefi
const byte LOGITECH_SET_REGISTER_REQUEST = 0x80;
const byte LOGITECH_GET_REGISTER_REQUEST = 0x81;
Dictionary<int, byte> map = new();
Dictionary<int, byte> map = [];
if (!deviceUsages.TryGetValue(1, out HidDevice? device) || !device.TryOpen(out HidStream stream))
return map;
@@ -40,13 +40,13 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" };
public static List<string> PossibleX86NativePaths { get; } = ["x86/LogitechLedEnginesWrapper.dll"];
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" };
public static List<string> PossibleX64NativePaths { get; } = ["x64/LogitechLedEnginesWrapper.dll"];
private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue;
@@ -162,7 +162,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// <summary>
/// Gets the HID-definitions for wireless per-device-devices.
/// </summary>
public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = new();
public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = [];
#endregion
@@ -17,7 +17,7 @@ internal static class _LogitechGSDK
{
#region Libary Management
private static IntPtr _handle = IntPtr.Zero;
private static nint _handle = 0;
/// <summary>
/// Reloads the SDK.
@@ -30,7 +30,7 @@ internal static class _LogitechGSDK
private static void LoadLogitechGSDK()
{
if (_handle != IntPtr.Zero) return;
if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@@ -70,21 +70,21 @@ internal static class _LogitechGSDK
internal static void UnloadLogitechGSDK()
{
if (_handle == IntPtr.Zero) return;
if (_handle == 0) return;
_logiLedInitPointer = IntPtr.Zero;
_logiLedShutdownPointer = IntPtr.Zero;
_logiLedSetTargetDevicePointer = IntPtr.Zero;
_logiLedGetSdkVersionPointer = IntPtr.Zero;
_lgiLedSaveCurrentLightingPointer = IntPtr.Zero;
_logiLedRestoreLightingPointer = IntPtr.Zero;
_logiLedSetLightingPointer = IntPtr.Zero;
_logiLedSetLightingForKeyWithKeyNamePointer = IntPtr.Zero;
_logiLedSetLightingFromBitmapPointer = IntPtr.Zero;
_logiLedSetLightingForTargetZonePointer = IntPtr.Zero;
_logiLedInitPointer = 0;
_logiLedShutdownPointer = 0;
_logiLedSetTargetDevicePointer = 0;
_logiLedGetSdkVersionPointer = 0;
_lgiLedSaveCurrentLightingPointer = 0;
_logiLedRestoreLightingPointer = 0;
_logiLedSetLightingPointer = 0;
_logiLedSetLightingForKeyWithKeyNamePointer = 0;
_logiLedSetLightingFromBitmapPointer = 0;
_logiLedSetLightingForTargetZonePointer = 0;
NativeLibrary.Free(_handle);
_handle = IntPtr.Zero;
_handle = 0;
}
#endregion
@@ -93,16 +93,16 @@ internal static class _LogitechGSDK
#region Pointers
private static IntPtr _logiLedInitPointer;
private static IntPtr _logiLedShutdownPointer;
private static IntPtr _logiLedSetTargetDevicePointer;
private static IntPtr _logiLedGetSdkVersionPointer;
private static IntPtr _lgiLedSaveCurrentLightingPointer;
private static IntPtr _logiLedRestoreLightingPointer;
private static IntPtr _logiLedSetLightingPointer;
private static IntPtr _logiLedSetLightingForKeyWithKeyNamePointer;
private static IntPtr _logiLedSetLightingFromBitmapPointer;
private static IntPtr _logiLedSetLightingForTargetZonePointer;
private static nint _logiLedInitPointer;
private static nint _logiLedShutdownPointer;
private static nint _logiLedSetTargetDevicePointer;
private static nint _logiLedGetSdkVersionPointer;
private static nint _lgiLedSaveCurrentLightingPointer;
private static nint _logiLedRestoreLightingPointer;
private static nint _logiLedSetLightingPointer;
private static nint _logiLedSetLightingForKeyWithKeyNamePointer;
private static nint _logiLedSetLightingFromBitmapPointer;
private static nint _logiLedSetLightingForTargetZonePointer;
#endregion
@@ -146,9 +146,9 @@ internal static class _LogitechGSDK
internal static unsafe bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage)
=> ((delegate* unmanaged[Cdecl]<LogitechDeviceType, int, int, int, int, bool>)ThrowIfZero(_logiLedSetLightingForTargetZonePointer))(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
private static IntPtr ThrowIfZero(IntPtr ptr)
private static nint ThrowIfZero(nint ptr)
{
if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Logitech-SDK is not initialized.");
if (ptr == 0) throw new RGBDeviceException("The Logitech-SDK is not initialized.");
return ptr;
}