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

@@ -40,8 +40,8 @@ public class CorsairDeviceUpdateQueue : UpdateQueue
try
{
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Length);
IntPtr addPtr = new(ptr.ToInt64());
nint ptr = Marshal.AllocHGlobal(structSize * dataSet.Length);
nint addPtr = ptr;
try
{
foreach ((object key, Color color) in dataSet)
@@ -55,7 +55,7 @@ public class CorsairDeviceUpdateQueue : UpdateQueue
};
Marshal.StructureToPtr(corsairColor, addPtr, false);
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
addPtr += structSize;
}
_CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr);
@@ -1,7 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
using System.Runtime.InteropServices;
using RGB.NET.Devices.CorsairLegacy.Native;
@@ -54,8 +53,8 @@ public class CorsairProtocolDetails
/// <param name="nativeDetails">The native CorsairProtocolDetails-struct</param>
internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails)
{
this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion);
this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion);
this.SdkVersion = nativeDetails.sdkVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion);
this.ServerVersion = nativeDetails.serverVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion);
this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion;
this.ServerProtocolVersion = nativeDetails.serverProtocolVersion;
this.BreakingChanges = nativeDetails.breakingChanges != 0;
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.CorsairLegacy.Native;
@@ -50,14 +49,14 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
if (nativeLedPositions == null) return;
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = nativeLedPositions.pLedPosition;
nint ptr = nativeLedPositions.pLedPosition;
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
{
_CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
if (ledPosition == null)
{
ptr = new IntPtr(ptr.ToInt64() + structSize);
ptr += structSize;
continue;
}
@@ -65,7 +64,7 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
Rectangle rectangle = ledPosition.ToRectangle();
AddLed(ledId, rectangle.Location, rectangle.Size);
ptr = new IntPtr(ptr.ToInt64() + structSize);
ptr += structSize;
}
}
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using RGB.NET.Core;
using RGB.NET.Devices.CorsairLegacy.Native;
@@ -65,7 +64,7 @@ public class CorsairRGBDeviceInfo : IRGBDeviceInfo
this.CorsairDeviceIndex = deviceIndex;
this.DeviceType = deviceType;
this.CorsairDeviceType = nativeInfo.type;
this.Model = nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase);
this.Model = nativeInfo.model == 0 ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase);
this.DeviceId = nativeInfo.deviceId ?? string.Empty;
this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;
@@ -34,27 +34,27 @@ public static class LedMappings
/// <summary>
/// Gets the mapping for graphics cards.
/// </summary>
public static LedMapping<CorsairLedId> GraphicsCard { get; } = new();
public static LedMapping<CorsairLedId> GraphicsCard { get; } = [];
/// <summary>
/// Gets the mapping for headsets.
/// </summary>
public static LedMapping<CorsairLedId> HeadsetStand { get; } = new();
public static LedMapping<CorsairLedId> HeadsetStand { get; } = [];
/// <summary>
/// Gets the mapping for mainboards.
/// </summary>
public static LedMapping<CorsairLedId> Mainboard { get; } = new();
public static LedMapping<CorsairLedId> Mainboard { get; } = [];
/// <summary>
/// Gets the mapping for memory.
/// </summary>
public static LedMapping<CorsairLedId> Memory { get; } = new();
public static LedMapping<CorsairLedId> Memory { get; } = [];
/// <summary>
/// Gets the mapping for mousepads.
/// </summary>
public static LedMapping<CorsairLedId> Mousepad { get; } = new();
public static LedMapping<CorsairLedId> Mousepad { get; } = [];
/// <summary>
/// Gets the mapping for headsets.