diff --git a/RGB.NET.Core/Decorators/AbstractDecorateable.cs b/RGB.NET.Core/Decorators/AbstractDecorateable.cs index 5312eab6..706aa450 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorateable.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorateable.cs @@ -11,7 +11,7 @@ public abstract class AbstractDecoratable : AbstractBindable, IDecoratable { #region Properties & Fields - private readonly List _decorators = new(); + private readonly List _decorators = []; /// public IReadOnlyList Decorators { get; } diff --git a/RGB.NET.Core/Decorators/AbstractDecorator.cs b/RGB.NET.Core/Decorators/AbstractDecorator.cs index 159fb4b2..2043ef6e 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorator.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorator.cs @@ -29,7 +29,7 @@ public int Order /// /// Gets a readonly-list of all this decorator is attached to. /// - protected List DecoratedObjects { get; } = new(); + protected List DecoratedObjects { get; } = []; #endregion @@ -46,14 +46,14 @@ public int Order /// protected virtual void Detach() { - List decoratables = new(DecoratedObjects); + List decoratables = [..DecoratedObjects]; foreach (IDecoratable decoratable in decoratables) { IEnumerable types = decoratable.GetType().GetInterfaces().Where(t => t.IsGenericType && (t.Name == typeof(IDecoratable<>).Name) && t.GenericTypeArguments[0].IsInstanceOfType(this)); foreach (Type decoratableType in types) - decoratableType.GetMethod(nameof(IDecoratable.RemoveDecorator))?.Invoke(decoratable, new object[] { this }); + decoratableType.GetMethod(nameof(IDecoratable.RemoveDecorator))?.Invoke(decoratable, [this]); } } diff --git a/RGB.NET.Core/Decorators/IDecoratable.cs b/RGB.NET.Core/Decorators/IDecoratable.cs index 5fddf47a..413b6980 100644 --- a/RGB.NET.Core/Decorators/IDecoratable.cs +++ b/RGB.NET.Core/Decorators/IDecoratable.cs @@ -6,8 +6,7 @@ namespace RGB.NET.Core; /// /// Represents a basic decoratable. /// -public interface IDecoratable : INotifyPropertyChanged -{ } +public interface IDecoratable : INotifyPropertyChanged; /// /// diff --git a/RGB.NET.Core/Decorators/ILedGroupDecorator.cs b/RGB.NET.Core/Decorators/ILedGroupDecorator.cs index 051ca9d8..51bd3022 100644 --- a/RGB.NET.Core/Decorators/ILedGroupDecorator.cs +++ b/RGB.NET.Core/Decorators/ILedGroupDecorator.cs @@ -4,5 +4,4 @@ /// /// Represents a basic decorator decorating a . /// -public interface ILedGroupDecorator : IDecorator -{ } \ No newline at end of file +public interface ILedGroupDecorator : IDecorator; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index a03bfa23..9e3572b3 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -53,7 +53,7 @@ public abstract class AbstractRGBDevice : Placeable, IRGBDevice /// Gets a dictionary containing all of the . /// - protected Dictionary LedMapping { get; } = new(); + protected Dictionary LedMapping { get; } = []; /// /// Gets the update queue used to update this device. diff --git a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs index 2d1f2eba..ff2f7df6 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs @@ -25,7 +25,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider /// /// The list of devices managed by this device-provider. /// - protected List InternalDevices { get; } = new(); + protected List InternalDevices { get; } = []; /// public virtual IReadOnlyList Devices => new ReadOnlyCollection(InternalDevices); @@ -34,7 +34,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider /// Gets the dictionary containing the registered update triggers. /// Normally should be used to access them. /// - protected Dictionary UpdateTriggerMapping { get; } = new(); + protected Dictionary UpdateTriggerMapping { get; } = []; /// public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList()); @@ -116,7 +116,7 @@ protected virtual IEnumerable GetLoadedDevices(RGBDeviceType loadFil { if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); - List devices = new(); + List devices = []; foreach (IRGBDevice device in LoadDevices()) { try @@ -189,7 +189,7 @@ protected virtual void Reset() foreach (IRGBDevice device in Devices) device.Dispose(); - List devices = new(InternalDevices); + List devices = [..InternalDevices]; foreach (IRGBDevice device in devices) RemoveDevice(device); diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs b/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs index 1e1eb2f2..da7c2a08 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs @@ -3,5 +3,4 @@ /// /// Represents a cooler-device /// -public interface ICooler : IRGBDevice -{ } \ No newline at end of file +public interface ICooler : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs b/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs index 3bb4c23a..a395d91f 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs @@ -3,5 +3,4 @@ /// /// Represents a DRAM-device /// -public interface IDRAM : IRGBDevice -{ } \ No newline at end of file +public interface IDRAM : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs b/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs index 9f0c803a..fd11b084 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs @@ -3,5 +3,4 @@ /// /// represents a fan-device /// -public interface IFan : IRGBDevice -{ } \ No newline at end of file +public interface IFan : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs b/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs index d2c55076..ebfe6a1e 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs @@ -3,5 +3,4 @@ /// /// Represents a gamecontroller-device /// -public interface IGameController: IRGBDevice -{ } \ No newline at end of file +public interface IGameController: IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs b/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs index 372ec092..9d589445 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs @@ -3,5 +3,4 @@ /// /// Represents a graphics-card-device /// -public interface IGraphicsCard : IRGBDevice -{ } \ No newline at end of file +public interface IGraphicsCard : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs b/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs index 0256cd5c..fea115e6 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs @@ -3,5 +3,4 @@ /// /// Represents a headset-device /// -public interface IHeadset : IRGBDevice -{ } \ No newline at end of file +public interface IHeadset : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs b/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs index 537c8564..afc31c7e 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs @@ -3,5 +3,4 @@ /// /// Represents a headset-stand-device /// -public interface IHeadsetStand : IRGBDevice -{ } \ No newline at end of file +public interface IHeadsetStand : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs b/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs index 2a65233b..ff6a9700 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs @@ -3,5 +3,4 @@ /// /// Represents a keypad-device /// -public interface IKeypad : IRGBDevice -{ } \ No newline at end of file +public interface IKeypad : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs b/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs index b0f401e5..48d029b2 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs @@ -3,5 +3,4 @@ /// /// Represents a led-matrix-device /// -public interface ILedMatrix : IRGBDevice -{ } \ No newline at end of file +public interface ILedMatrix : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs b/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs index 4bb5fd80..355cd280 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs @@ -3,5 +3,4 @@ /// /// Represents a led-stripe-device /// -public interface ILedStripe : IRGBDevice -{ } \ No newline at end of file +public interface ILedStripe : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs index 10af8f4a..5e7b270d 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs @@ -3,5 +3,4 @@ /// /// Represents a mainboard-device /// -public interface IMainboard : IRGBDevice -{ } \ No newline at end of file +public interface IMainboard : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs index 76e62e2e..d0459760 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs @@ -3,5 +3,4 @@ /// /// Represents a mouse-device /// -public interface IMouse : IRGBDevice -{ } \ No newline at end of file +public interface IMouse : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs index c89b2548..af875217 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs @@ -3,5 +3,4 @@ /// /// Represents a mousepad-device /// -public interface IMousepad : IRGBDevice -{ } \ No newline at end of file +public interface IMousepad : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs b/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs index cde47e4e..226d6a8d 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs @@ -3,5 +3,4 @@ /// /// Represents a speaker-device /// -public interface ISpeaker : IRGBDevice -{ } \ No newline at end of file +public interface ISpeaker : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs index 1d136ad7..a0374536 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs @@ -3,5 +3,4 @@ /// /// Represents a device with unkown or not specified type. /// -public interface IUnknownDevice : IRGBDevice -{ } \ No newline at end of file +public interface IUnknownDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs index a0d648be..5a856e5a 100644 --- a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs +++ b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs @@ -2,22 +2,13 @@ namespace RGB.NET.Core; -public sealed class DevicesChangedEventArgs : EventArgs +public sealed class DevicesChangedEventArgs(IRGBDevice device, DevicesChangedEventArgs.DevicesChangedAction action) + : EventArgs { #region Properties & Fields - public IRGBDevice Device { get; } - public DevicesChangedAction Action { get; } - - #endregion - - #region Constructors - - public DevicesChangedEventArgs(IRGBDevice device, DevicesChangedAction action) - { - this.Device = device; - this.Action = action; - } + public IRGBDevice Device { get; } = device; + public DevicesChangedAction Action { get; } = action; #endregion diff --git a/RGB.NET.Core/Events/UpdatedEventArgs.cs b/RGB.NET.Core/Events/UpdatedEventArgs.cs index b4251d4d..467e5033 100644 --- a/RGB.NET.Core/Events/UpdatedEventArgs.cs +++ b/RGB.NET.Core/Events/UpdatedEventArgs.cs @@ -6,5 +6,4 @@ namespace RGB.NET.Core; /// /// Represents the information supplied with an -event. /// -public class UpdatedEventArgs : EventArgs -{ } \ No newline at end of file +public class UpdatedEventArgs : EventArgs; \ No newline at end of file diff --git a/RGB.NET.Core/Extensions/RectangleExtensions.cs b/RGB.NET.Core/Extensions/RectangleExtensions.cs index 68fec324..c97256fd 100644 --- a/RGB.NET.Core/Extensions/RectangleExtensions.cs +++ b/RGB.NET.Core/Extensions/RectangleExtensions.cs @@ -151,12 +151,13 @@ public static bool Contains(this in Rectangle rect, in Rectangle rect2) => (rect /// A array of containing the new locations of the corners of the original rectangle. public static Point[] Rotate(this in Rectangle rect, in Rotation rotation, in Point origin = new()) { - Point[] points = { - rect.Location, // top left - new(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right - new(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right - new(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right - }; + Point[] points = + [ + rect.Location, // top left + new Point(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right + new Point(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right + new Point(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right + ]; float sin = MathF.Sin(rotation.Radians); float cos = MathF.Cos(rotation.Radians); diff --git a/RGB.NET.Core/Helper/TimerHelper.cs b/RGB.NET.Core/Helper/TimerHelper.cs index 432170bf..e2742ab4 100644 --- a/RGB.NET.Core/Helper/TimerHelper.cs +++ b/RGB.NET.Core/Helper/TimerHelper.cs @@ -46,7 +46,7 @@ public static bool UseHighResolutionTimers } // ReSharper disable once InconsistentNaming - private static readonly HashSet _timerLeases = new(); + private static readonly HashSet _timerLeases = []; #endregion @@ -143,7 +143,7 @@ private static void DisableHighResolutionTimers() /// public static void DisposeAllHighResolutionTimerRequests() { - List timerLeases = new(_timerLeases); + List timerLeases = [.._timerLeases]; foreach (HighResolutionTimerDisposable timer in timerLeases) timer.Dispose(); } diff --git a/RGB.NET.Core/Ids/IdGenerator.cs b/RGB.NET.Core/Ids/IdGenerator.cs index c6270e7c..f9bf2177 100644 --- a/RGB.NET.Core/Ids/IdGenerator.cs +++ b/RGB.NET.Core/Ids/IdGenerator.cs @@ -12,9 +12,9 @@ public static class IdGenerator #region Properties & Fields // ReSharper disable InconsistentNaming - private static readonly HashSet _registeredIds = new(); - private static readonly Dictionary> _idMappings = new(); - private static readonly Dictionary> _counter = new(); + private static readonly HashSet _registeredIds = []; + private static readonly Dictionary> _idMappings = []; + private static readonly Dictionary> _counter = []; // ReSharper restore InconsistentNaming #endregion @@ -33,8 +33,8 @@ internal static string MakeUnique(Assembly callingAssembly, string id) { if (!_idMappings.TryGetValue(callingAssembly, out Dictionary? idMapping)) { - _idMappings.Add(callingAssembly, idMapping = new Dictionary()); - _counter.Add(callingAssembly, new Dictionary()); + _idMappings.Add(callingAssembly, idMapping = []); + _counter.Add(callingAssembly, []); } Dictionary counterMapping = _counter[callingAssembly]; diff --git a/RGB.NET.Core/Leds/LedMapping.cs b/RGB.NET.Core/Leds/LedMapping.cs index 0aab16d7..a296bbe2 100644 --- a/RGB.NET.Core/Leds/LedMapping.cs +++ b/RGB.NET.Core/Leds/LedMapping.cs @@ -13,14 +13,14 @@ public sealed class LedMapping : IEnumerable<(LedId ledId, T mapping)> { #region Constants - public static LedMapping Empty { get; } = new(); + public static LedMapping Empty { get; } = []; #endregion #region Properties & Fields - private readonly Dictionary _mapping = new(); - private readonly Dictionary _reverseMapping = new(); + private readonly Dictionary _mapping = []; + private readonly Dictionary _reverseMapping = []; /// /// Gets the number of entries in this mapping. diff --git a/RGB.NET.Core/MVVM/IBindable.cs b/RGB.NET.Core/MVVM/IBindable.cs index 24d1fa52..97192886 100644 --- a/RGB.NET.Core/MVVM/IBindable.cs +++ b/RGB.NET.Core/MVVM/IBindable.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Core; /// /// Represents a basic bindable class which notifies when a property value changes. /// -public interface IBindable : INotifyPropertyChanged -{ } \ No newline at end of file +public interface IBindable : INotifyPropertyChanged; \ No newline at end of file diff --git a/RGB.NET.Core/Misc/AbstractReferenceCounting.cs b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs index 09d64ef4..f55c56ab 100644 --- a/RGB.NET.Core/Misc/AbstractReferenceCounting.cs +++ b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs @@ -6,7 +6,7 @@ public abstract class AbstractReferenceCounting : IReferenceCounting { #region Properties & Fields - private readonly HashSet _referencingObjects = new(); + private readonly HashSet _referencingObjects = []; /// public int ActiveReferenceCount diff --git a/RGB.NET.Core/Misc/ActionDisposable.cs b/RGB.NET.Core/Misc/ActionDisposable.cs index 843605e0..7844a571 100644 --- a/RGB.NET.Core/Misc/ActionDisposable.cs +++ b/RGB.NET.Core/Misc/ActionDisposable.cs @@ -2,26 +2,11 @@ namespace RGB.NET.Core; -public sealed class ActionDisposable : IDisposable +public sealed class ActionDisposable(Action onDispose) : IDisposable { - #region Properties & Fields - - private readonly Action _onDispose; - - #endregion - - #region Constructors - - public ActionDisposable(Action onDispose) - { - this._onDispose = onDispose; - } - - #endregion - #region Methods - public void Dispose() => _onDispose(); + public void Dispose() => onDispose(); #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 8219191b..5c3387fc 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -22,7 +22,7 @@ public sealed class RGBSurface : AbstractBindable, IDisposable private readonly IList _devices = new List(); private readonly IList _updateTriggers = new List(); - private readonly List _ledGroups = new(); + private readonly List _ledGroups = []; /// /// Gets a readonly list containing all loaded . @@ -184,7 +184,7 @@ public void Dispose() { List devices; lock (Devices) - devices = new List(_devices); + devices = [.._devices]; foreach (IRGBDevice device in devices) try { Detach(device); } diff --git a/RGB.NET.Core/Update/CustomUpdateData.cs b/RGB.NET.Core/Update/CustomUpdateData.cs index 4888cd1b..736723a8 100644 --- a/RGB.NET.Core/Update/CustomUpdateData.cs +++ b/RGB.NET.Core/Update/CustomUpdateData.cs @@ -52,7 +52,7 @@ public sealed class CustomUpdateData : ICustomUpdateData { #region Properties & Fields - private readonly Dictionary _data = new(); + private readonly Dictionary _data = []; #endregion diff --git a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs index 29433790..03a3e65e 100644 --- a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs @@ -31,5 +31,4 @@ public interface IUpdateQueue : IReferenceCounting, IDisposa /// /// Represents a generic update queue processing -data using -identifiers. /// -public interface IUpdateQueue : IUpdateQueue -{ } \ No newline at end of file +public interface IUpdateQueue : IUpdateQueue; \ No newline at end of file diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index c17e3a9f..22ef7f9e 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -16,7 +16,7 @@ public abstract class UpdateQueue : AbstractReferenceCountin private readonly object _dataLock = new(); private readonly IDeviceUpdateTrigger _updateTrigger; - private readonly Dictionary _currentDataSet = new(); + private readonly Dictionary _currentDataSet = []; /// public bool RequiresFlush { get; private set; } diff --git a/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs index cb7d4a93..027c83a5 100644 --- a/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a asus RGB-device. /// -public interface IAsusRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IAsusRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index ee5f5498..12004290 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -25,8 +25,8 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice? _ledMapping; - private readonly Dictionary _ledAsusLed = new(); - private readonly Dictionary _ledAsusLights = new(); + private readonly Dictionary _ledAsusLed = []; + private readonly Dictionary _ledAsusLights = []; IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo; @@ -35,11 +35,11 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDeviceNote: These LED mappings should be based on light indexes. /// // ReSharper disable once InconsistentNaming - public static readonly List ExtraLedMappings = new() - { - new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), - new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) - }; + public static readonly List ExtraLedMappings = + [ + new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), + new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) + ]; #endregion @@ -66,7 +66,7 @@ internal AsusKeyboardRGBDevice(AsusKeyboardRGBDeviceInfo info, LedMapping to get the real model /// - private static readonly List GENERIC_DEVICE_NAMES = new() { "NotebookKeyboard" }; + private static readonly List GENERIC_DEVICE_NAMES = ["NotebookKeyboard"]; /// public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown; diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 8678e1a1..cecc41d1 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -37,13 +37,13 @@ public static CoolerMasterDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/CMSDK.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/CMSDK.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/CMSDK.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/CMSDK.dll"]; #endregion diff --git a/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs index 5cf66bba..8c1fb926 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents a CoolerMaster RGB-device. /// -public interface ICoolerMasterRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface ICoolerMasterRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs index 6b51c39a..6be82b07 100644 --- a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs +++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs @@ -16,14 +16,14 @@ internal static class _CoolerMasterSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. /// internal static void Reload() { - if (_handle != IntPtr.Zero) + if (_handle != 0) { foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes))) EnableLedControl(false, index); @@ -34,7 +34,7 @@ internal static void Reload() private static void LoadCMSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; // HACK: Load library at runtime to support both, x86 and x64 with one managed dll List possiblePathList = (Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths) @@ -47,7 +47,7 @@ private static void LoadCMSDK() #if NET6_0 if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}"); #else - if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); + if (_handle == 0) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); #endif _getSDKVersionPointer = (GetSDKVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_handle, "GetCM_SDK_DllVer"), typeof(GetSDKVersionPointer)); @@ -62,7 +62,7 @@ private static void LoadCMSDK() internal static void UnloadCMSDK() { - if (_handle == IntPtr.Zero) return; + if (_handle == 0) return; _getSDKVersionPointer = null; _setControlDevicenPointer = null; @@ -74,14 +74,14 @@ internal static void UnloadCMSDK() _setAllLedColorPointer = null; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - private static extern IntPtr LoadLibrary(string dllToLoad); + private static extern nint LoadLibrary(string dllToLoad); [DllImport("kernel32.dll", CharSet = CharSet.Ansi)] - private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name); + private static extern nint GetProcAddress(nint dllHandle, string name); #endregion diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 3a4a4dac..4dba9ea8 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -37,13 +37,13 @@ public static CorsairDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/iCUESDK.dll", "x86/CUESDK_2019.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/iCUESDK.dll", "x86/CUESDK_2019.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/iCUESDK.dll", "x64/iCUESDK.x64_2019.dll", "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/iCUESDK.dll", "x64/iCUESDK.x64_2019.dll", "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll"]; /// /// Gets or sets the timeout used when connecting to the SDK. diff --git a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs index f37ec876..58e99376 100644 --- a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs @@ -165,7 +165,7 @@ internal static class LedMappings internal static LedMapping CreateMapping(IEnumerable ids, LedId referenceId) { - LedMapping mapping = new(); + LedMapping mapping = []; int counter = 0; foreach (CorsairLedId corsairLedId in ids.OrderBy(x => x)) mapping.Add(referenceId + counter++, corsairLedId); diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs index f598d27c..c2005c50 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs @@ -19,6 +19,7 @@ internal sealed class _CorsairDeviceFilter /// /// iCUE-SDK: mask that describes device types, formed as logical “or” of CorsairDeviceType enum values /// + // ReSharper disable once NotAccessedField.Global internal CorsairDeviceType deviceTypeMask; #endregion diff --git a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs index f82bec28..9f770e8e 100644 --- a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs @@ -38,13 +38,13 @@ public static CorsairLegacyDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll"]; /// /// Gets the protocol details for the current SDK-connection. @@ -170,7 +170,7 @@ private IEnumerable LoadCorsairDevices() foreach (_CorsairChannelInfo channelInfo in channels) { int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo)); - IntPtr channelDeviceInfoPtr = channelInfo.devices; + nint channelDeviceInfoPtr = channelInfo.devices; for (int device = 0; (device < channelInfo.devicesCount) && (ledOffset < nativeDeviceInfo.ledsCount); device++) { _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!; @@ -178,7 +178,7 @@ private IEnumerable LoadCorsairDevices() yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, channelDeviceInfo, ledOffset), updateQueue); ledOffset += channelDeviceInfo.deviceLedCount; - channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); + channelDeviceInfoPtr += channelDeviceInfoStructSize; } } break; @@ -195,13 +195,13 @@ private static IEnumerable<_CorsairChannelInfo> GetChannels(_CorsairDeviceInfo d _CorsairChannelsInfo? channelsInfo = deviceInfo.channels; if (channelsInfo == null) yield break; - IntPtr channelInfoPtr = channelsInfo.channels; + nint channelInfoPtr = channelsInfo.channels; for (int channel = 0; channel < channelsInfo.channelsCount; channel++) { yield return (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo))!; int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo)); - channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize); + channelInfoPtr += channelInfoStructSize; } } diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs index c285e5a6..cc2b57b5 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs @@ -1,7 +1,6 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global -using System; using System.Linq; using System.Runtime.InteropServices; using RGB.NET.Core; @@ -24,7 +23,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the custom-device. /// The queue used to update this device. internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, new LedMapping(), updateQueue) + : base(info, [], updateQueue) { } #endregion @@ -40,7 +39,7 @@ protected override void InitializeLayout() if (nativeLedPositions == null) return; int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); - IntPtr ptr = new(nativeLedPositions.pLedPosition.ToInt64() + (structSize * DeviceInfo.LedOffset)); + nint ptr = nativeLedPositions.pLedPosition + (structSize * DeviceInfo.LedOffset); LedId referenceLedId = GetReferenceLed(DeviceInfo.DeviceType); for (int i = 0; i < DeviceInfo.LedCount; i++) @@ -49,7 +48,7 @@ protected override void InitializeLayout() _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); if (ledPosition == null) { - ptr = new IntPtr(ptr.ToInt64() + structSize); + ptr += structSize; continue; } @@ -60,7 +59,7 @@ protected override void InitializeLayout() Rectangle rectangle = ledPosition.ToRectangle(); AddLed(ledId, rectangle.Location, rectangle.Size); - ptr = new IntPtr(ptr.ToInt64() + structSize); + ptr += structSize; } if (DeviceInfo.LedOffset > 0) diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs index 3664f0d6..783089e9 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs @@ -41,7 +41,7 @@ public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo /// The offset used to find the LEDs of this device. internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, int ledOffset) : base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, - GetModelName(nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo)) + GetModelName(nativeInfo.model == 0 ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo)) { this.LedOffset = ledOffset; diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs index 6282932b..a7669117 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs @@ -40,8 +40,8 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe 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 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe }; Marshal.StructureToPtr(corsairColor, addPtr, false); - addPtr = new IntPtr(addPtr.ToInt64() + structSize); + addPtr += structSize; } _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr); diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs index f2cd5207..8bab4b46 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs @@ -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 /// The native CorsairProtocolDetails-struct 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; diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs index fb9aa2ed..e86a92ae 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs @@ -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 @@ protected virtual void InitializeLayout() 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 @@ protected virtual void InitializeLayout() Rectangle rectangle = ledPosition.ToRectangle(); AddLed(ledId, rectangle.Location, rectangle.Size); - ptr = new IntPtr(ptr.ToInt64() + structSize); + ptr += structSize; } } diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs index f35a65c6..87151855 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs @@ -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 @@ internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _Corsai 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; diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs index ca2da702..d528c2e7 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs @@ -34,27 +34,27 @@ static LedMappings() /// /// Gets the mapping for graphics cards. /// - public static LedMapping GraphicsCard { get; } = new(); + public static LedMapping GraphicsCard { get; } = []; /// /// Gets the mapping for headsets. /// - public static LedMapping HeadsetStand { get; } = new(); + public static LedMapping HeadsetStand { get; } = []; /// /// Gets the mapping for mainboards. /// - public static LedMapping Mainboard { get; } = new(); + public static LedMapping Mainboard { get; } = []; /// /// Gets the mapping for memory. /// - public static LedMapping Memory { get; } = new(); + public static LedMapping Memory { get; } = []; /// /// Gets the mapping for mousepads. /// - public static LedMapping Mousepad { get; } = new(); + public static LedMapping Mousepad { get; } = []; /// /// Gets the mapping for headsets. diff --git a/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs b/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs index e153e7a4..0da20e5e 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs @@ -7,7 +7,7 @@ internal static class NativeExtensions { internal static Rectangle ToRectangle(this _CorsairLedPosition position) { - //HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0. + //HACK DarthAffe 08.07.2018: It seems like corsair introduced a issue here - it's always 0. float width = position.width < 0.5f ? 10 : (float)position.width; float height = position.height < 0.5f ? 10 : (float)position.height; float posX = (float)position.left; diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs index 718f446d..3ace4359 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs @@ -16,7 +16,7 @@ internal static class _CUESDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadCUESDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -71,23 +71,23 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadCUESDK() { - if (_handle == IntPtr.Zero) return; - - _corsairSetLedsColorsBufferByDeviceIndexPointer = IntPtr.Zero; - _corsairSetLedsColorsFlushBufferPointer = IntPtr.Zero; - _corsairGetLedsColorsByDeviceIndexPointer = IntPtr.Zero; - _corsairSetLayerPriorityPointer = IntPtr.Zero; - _corsairGetDeviceCountPointer = IntPtr.Zero; - _corsairGetDeviceInfoPointer = IntPtr.Zero; - _corsairGetLedIdForKeyNamePointer = IntPtr.Zero; - _corsairGetLedPositionsByDeviceIndexPointer = IntPtr.Zero; - _corsairRequestControlPointer = IntPtr.Zero; - _corsairReleaseControlPointer = IntPtr.Zero; - _corsairPerformProtocolHandshakePointer = IntPtr.Zero; - _corsairGetLastErrorPointer = IntPtr.Zero; + if (_handle == 0) return; + + _corsairSetLedsColorsBufferByDeviceIndexPointer = 0; + _corsairSetLedsColorsFlushBufferPointer = 0; + _corsairGetLedsColorsByDeviceIndexPointer = 0; + _corsairSetLayerPriorityPointer = 0; + _corsairGetDeviceCountPointer = 0; + _corsairGetDeviceInfoPointer = 0; + _corsairGetLedIdForKeyNamePointer = 0; + _corsairGetLedPositionsByDeviceIndexPointer = 0; + _corsairRequestControlPointer = 0; + _corsairReleaseControlPointer = 0; + _corsairPerformProtocolHandshakePointer = 0; + _corsairGetLastErrorPointer = 0; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -96,18 +96,18 @@ internal static void UnloadCUESDK() #region Pointers - private static IntPtr _corsairSetLedsColorsBufferByDeviceIndexPointer; - private static IntPtr _corsairSetLedsColorsFlushBufferPointer; - private static IntPtr _corsairGetLedsColorsByDeviceIndexPointer; - private static IntPtr _corsairSetLayerPriorityPointer; - private static IntPtr _corsairGetDeviceCountPointer; - private static IntPtr _corsairGetDeviceInfoPointer; - private static IntPtr _corsairGetLedIdForKeyNamePointer; - private static IntPtr _corsairGetLedPositionsByDeviceIndexPointer; - private static IntPtr _corsairRequestControlPointer; - private static IntPtr _corsairReleaseControlPointer; - private static IntPtr _corsairPerformProtocolHandshakePointer; - private static IntPtr _corsairGetLastErrorPointer; + private static nint _corsairSetLedsColorsBufferByDeviceIndexPointer; + private static nint _corsairSetLedsColorsFlushBufferPointer; + private static nint _corsairGetLedsColorsByDeviceIndexPointer; + private static nint _corsairSetLayerPriorityPointer; + private static nint _corsairGetDeviceCountPointer; + private static nint _corsairGetDeviceInfoPointer; + private static nint _corsairGetLedIdForKeyNamePointer; + private static nint _corsairGetLedPositionsByDeviceIndexPointer; + private static nint _corsairRequestControlPointer; + private static nint _corsairReleaseControlPointer; + private static nint _corsairPerformProtocolHandshakePointer; + private static nint _corsairGetLastErrorPointer; #endregion @@ -118,8 +118,8 @@ internal static void UnloadCUESDK() /// and follows after one or more calls of CorsairSetLedsColorsBufferByDeviceIndex to set the LEDs buffer. /// This function does not take logical layout into account. /// - internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors); + internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, nint ledsColors) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors); /// /// CUE-SDK: writes to the devices LEDs colors buffer which is previously filled by the CorsairSetLedsColorsBufferByDeviceIndex function. @@ -132,8 +132,8 @@ internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIn /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. /// This function works for keyboard, mouse, mousemat, headset, headset stand and DIY-devices. /// - internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors); + internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, nint ledsColors) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors); /// /// CUE-SDK: set layer priority for this shared client. @@ -150,12 +150,12 @@ internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, i /// /// CUE-SDK: returns information about device at provided index. /// - internal static unsafe IntPtr CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex); + internal static unsafe nint CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex); /// /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. /// - internal static unsafe IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex); + internal static unsafe nint CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex); /// /// CUE-SDK: retrieves led id for key name taking logical layout into account. @@ -183,9 +183,9 @@ internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, i /// internal static unsafe CorsairError CorsairGetLastError() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLastErrorPointer))(); - private static IntPtr ThrowIfZero(IntPtr ptr) + private static nint ThrowIfZero(nint ptr) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Corsair-SDK is not initialized."); + if (ptr == 0) throw new RGBDeviceException("The Corsair-SDK is not initialized."); return ptr; } diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs index c30bfe6a..82c07b85 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs @@ -3,7 +3,6 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -29,5 +28,5 @@ internal class _CorsairChannelInfo /// CUE-SDK: array containing information about each separate LED-device connected to the channel controlled by the DIY device. /// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device. /// - internal IntPtr devices; + internal nint devices; } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs index 61900b92..3dd7d04b 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs @@ -3,7 +3,6 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -24,5 +23,5 @@ internal class _CorsairChannelsInfo /// CUE-SDK: array containing information about each separate channel of the DIY-device. /// Index of the channel in the array is same as index of the channel on the DIY-device. /// - internal IntPtr channels; + internal nint channels; } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs index af3c03e7..f2f7eb80 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs @@ -3,7 +3,6 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -23,7 +22,7 @@ internal class _CorsairDeviceInfo /// /// CUE-SDK: null - terminated device model(like “K95RGB”) /// - internal IntPtr model; + internal nint model; /// /// CUE-SDK: enum describing physical layout of the keyboard or mouse diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs index db3d41d6..a3f0dbd0 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs @@ -2,7 +2,6 @@ #pragma warning disable 414 // Field 'x' is assigned but its value never used #pragma warning disable 649 // Field 'x' is never assigned -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -22,5 +21,5 @@ internal class _CorsairLedPositions /// /// CUE-SDK: array of led positions /// - internal IntPtr pLedPosition; + internal nint pLedPosition; } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs index 23a54777..5b85faad 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs @@ -2,7 +2,6 @@ #pragma warning disable 414 // Field 'x' is assigned but its value never used #pragma warning disable 649 // Field 'x' is never assigned -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -17,12 +16,12 @@ internal struct _CorsairProtocolDetails /// /// CUE-SDK: null - terminated string containing version of SDK(like “1.0.0.1”). Always contains valid value even if there was no CUE found /// - internal IntPtr sdkVersion; + internal nint sdkVersion; /// /// CUE-SDK: null - terminated string containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found. /// - internal IntPtr serverVersion; + internal nint serverVersion; /// /// CUE-SDK: integer number that specifies version of protocol that is implemented by current SDK. diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index d5f2456a..b5d725c3 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -35,7 +35,7 @@ public static DMXDeviceProvider Instance /// /// Gets a list of all defined device-definitions. /// - public List DeviceDefinitions { get; } = new(); + public List DeviceDefinitions { get; } = []; #endregion diff --git a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs index 8e0934bb..b8b8336d 100644 --- a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs +++ b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs @@ -55,7 +55,7 @@ public sealed class E131DMXDeviceDefinition : IDMXDeviceDefinition /// /// Gets or sets the led-mappings used to create the device. /// - public Dictionary getValueFunc)>> Leds { get; } = new(); + public Dictionary getValueFunc)>> Leds { get; } = []; /// /// The time in ms after which the device is updated even if no changes are made in the meantime to prevent the target from timing out or similar problems. diff --git a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs index 7ebdab83..600a1ea2 100644 --- a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs +++ b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs @@ -21,7 +21,7 @@ public sealed class E131UpdateQueue : UpdateQueue /// Gets the byte-representation of a E1.31 packet as described in http://tsp.esta.org/tsp/documents/docs/E1-31-2016.pdf. /// CID, SequenceNumber, Universe and PropertyValues needs to be updated before use! /// - internal byte[] DataPacket { get; } = { 0x00, 0x10, 0x00, 0x00, 0x41, 0x53, 0x43, 0x2D, 0x45, 0x31, 0x2E, 0x31, 0x37, 0x00, 0x00, 0x00, 0x72, 0x6E, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x58, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x72, 0x0B, 0x02, 0xA1, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + internal byte[] DataPacket { get; } = [0x00, 0x10, 0x00, 0x00, 0x41, 0x53, 0x43, 0x2D, 0x45, 0x31, 0x2E, 0x31, 0x37, 0x00, 0x00, 0x00, 0x72, 0x6E, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x58, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x72, 0x0B, 0x02, 0xA1, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; /// /// The sequence-number used to detect the order in which packages where sent. diff --git a/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs b/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs index 5ec87dfc..0700b3f5 100644 --- a/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs +++ b/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs @@ -3,5 +3,4 @@ /// /// Marker interface for DMX device definitions. /// -public interface IDMXDeviceDefinition -{ } \ No newline at end of file +public interface IDMXDeviceDefinition; \ No newline at end of file diff --git a/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs b/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs index aa1aa296..4f9359f2 100644 --- a/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs +++ b/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs @@ -5,20 +5,12 @@ namespace RGB.NET.Devices.DMX; -internal sealed class LedChannelMapping : IEnumerable<(int channel, Func getValue)> +internal sealed class LedChannelMapping(List<(int channel, Func getValue)> mappings) + : IEnumerable<(int channel, Func getValue)> { #region Properties & Fields - private readonly List<(int channel, Func getValue)> _mappings; - - #endregion - - #region Constructors - - public LedChannelMapping(List<(int channel, Func getValue)> mappings) - { - this._mappings = new List<(int channel, Func getValue)>(mappings); - } + private readonly List<(int channel, Func getValue)> _mappings = [..mappings]; #endregion diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs index 836c6db6..636e57f9 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs @@ -32,7 +32,7 @@ public static DebugDeviceProvider Instance } } - private List<(IDeviceLayout layout, Action>? updateLedsAction)> _fakeDeviceDefinitions = new(); + private readonly List<(IDeviceLayout layout, Action>? updateLedsAction)> _fakeDeviceDefinitions = []; #endregion diff --git a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs index 2789821c..df86acca 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs @@ -3,16 +3,8 @@ namespace RGB.NET.Devices.Debug; -internal sealed class DebugDeviceUpdateQueue : UpdateQueue +internal sealed class DebugDeviceUpdateQueue() : UpdateQueue(new DeviceUpdateTrigger()) { - #region Constructors - - public DebugDeviceUpdateQueue() - : base(new DeviceUpdateTrigger()) - { } - - #endregion - #region Methods protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true; diff --git a/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs b/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs index 9ff7cc90..4bcdfe37 100644 --- a/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents a logitech RGB-device. /// -public interface ILogitechRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface ILogitechRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs index 355e4573..de498815 100644 --- a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs +++ b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs @@ -23,20 +23,20 @@ public sealed class LightspeedHIDLoader : IEnumerable RECEIVER_PIDS = new() - { - 0xC539, - 0xC53A, - 0xC541, - 0xC545, - 0xC547 - }; + private static readonly List RECEIVER_PIDS = + [ + 0xC539, + 0xC53A, + 0xC541, + 0xC545, + 0xC547 + ]; #endregion #region Properties & Fields - private readonly Dictionary> _deviceDefinitions = new(); + private readonly Dictionary> _deviceDefinitions = []; /// /// Gets the vendor id used for this loader. @@ -117,7 +117,7 @@ private Dictionary GetWirelessDevices(IReadOnlyDictionary map = new(); + Dictionary map = []; if (!deviceUsages.TryGetValue(1, out HidDevice? device) || !device.TryOpen(out HidStream stream)) return map; diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index 4a12b395..22411f80 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -40,13 +40,13 @@ public static LogitechDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/LogitechLedEnginesWrapper.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/LogitechLedEnginesWrapper.dll"]; private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue; private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue; @@ -162,7 +162,7 @@ public static LogitechDeviceProvider Instance /// /// Gets the HID-definitions for wireless per-device-devices. /// - public static LightspeedHIDLoader PerDeviceWirelessDeviceDefinitions { get; } = new(); + public static LightspeedHIDLoader PerDeviceWirelessDeviceDefinitions { get; } = []; #endregion diff --git a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs index 76efa36b..42ebb6cc 100644 --- a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs +++ b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs @@ -17,7 +17,7 @@ internal static class _LogitechGSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -30,7 +30,7 @@ internal static void Reload() private static void LoadLogitechGSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -70,21 +70,21 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadLogitechGSDK() { - if (_handle == IntPtr.Zero) 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; + if (_handle == 0) return; + + _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 void UnloadLogitechGSDK() #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 unsafe bool LogiLedSetLightingFromBitmap(byte[] bitmap) internal static unsafe bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage) => ((delegate* unmanaged[Cdecl])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; } diff --git a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs index b8807531..b6b83613 100644 --- a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Msi; /// /// Represents a MSI RGB-device. /// -public interface IMsiRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IMsiRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 1a305cc5..54be621b 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -37,13 +37,13 @@ public static MsiDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/MysticLight_SDK.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/MysticLight_SDK.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/MysticLight_SDK.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/MysticLight_SDK.dll"]; #endregion diff --git a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs index c13ef81f..1bc63fd6 100644 --- a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs +++ b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs @@ -16,7 +16,7 @@ internal static class _MsiSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadMsiSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -75,7 +75,7 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadMsiSDK() { - if (_handle == IntPtr.Zero) return; + if (_handle == 0) return; _initializePointer = null; _getDeviceInfoPointer = null; @@ -93,7 +93,7 @@ internal static void UnloadMsiSDK() _getErrorMessagePointer = null; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] diff --git a/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs index 6b8e05ca..e59696e4 100644 --- a/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Novation; /// /// Represents a novation RGB-device. /// -public interface INovationRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface INovationRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs index 62795930..aa3f53d5 100644 --- a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs @@ -12,7 +12,7 @@ public sealed class RGBColorUpdateQueue : MidiUpdateQueue #region Properties & Fields private static readonly (Color, int)[] COLOR_PALETTE = - { + [ (new Color(0, 0, 0), 0), (new Color(28, 28, 28), 1), (new Color(124, 124, 124), 2), @@ -130,8 +130,8 @@ private static readonly (Color, int)[] COLOR_PALETTE = (new Color(0, 64, 0), 123), (new Color(61, 48, 0), 125), (new Color(180, 93, 0), 126), - (new Color(74, 20, 0), 127), - }; + (new Color(74, 20, 0), 127) + ]; #endregion diff --git a/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs b/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs index 7659d948..1235c909 100644 --- a/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs +++ b/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.OpenRGB; /// /// Represents a generic OpenRGB Device. /// -public interface IOpenRGBDevice : IRGBDevice -{ } +public interface IOpenRGBDevice : IRGBDevice; diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 4ad82cc6..26b3a2a9 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -17,7 +17,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider // ReSharper disable once InconsistentNaming private static readonly object _lock = new(); - private readonly List _clients = new(); + private readonly List _clients = []; private static OpenRGBDeviceProvider? _instance; @@ -36,7 +36,7 @@ public static OpenRGBDeviceProvider Instance /// /// Gets a list of all defined device-definitions. /// - public List DeviceDefinitions { get; } = new(); + public List DeviceDefinitions { get; } = []; /// /// Indicates whether all devices will be added, or just the ones with a 'Direct' mode. Defaults to false. diff --git a/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs b/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs index 85c6c0b4..937b6b8a 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs @@ -12,7 +12,7 @@ public static class LedMappings /// /// Gets the defautlt offset-mapping. /// - public static LedMapping StripeMapping = new(); + public static LedMapping StripeMapping = []; #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs index c7994609..ebcdff51 100644 --- a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs +++ b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs @@ -49,7 +49,7 @@ public static PicoPiDeviceProvider Instance { PicoPiSDK.HID_BULK_CONTROLLER_PID, RGBDeviceType.LedStripe, "WS2812B-Controller", LedMappings.StripeMapping, 0 }, }; - private readonly List _sdks = new(); + private readonly List _sdks = []; /// /// Gets or sets the endpoint used to update devices. (default ). diff --git a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs index 3d63bf02..17b7add5 100644 --- a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerChromaLinkUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS]; @@ -35,14 +35,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _ChromaLinkCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateChromaLinkEffect(_Defines.CHROMALINK_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateChromaLinkEffect(_Defines.CHROMALINK_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs b/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs index 35a38714..5ae8b822 100644 --- a/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer RGB-device. /// -public interface IRazerRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IRazerRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Generic/LedMappings.cs b/RGB.NET.Devices.Razer/Generic/LedMappings.cs index 373aae71..d1a3dabb 100644 --- a/RGB.NET.Devices.Razer/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Razer/Generic/LedMappings.cs @@ -386,20 +386,20 @@ public static class LedMappings /// /// Gets the mapping for mousepads. /// - public static LedMapping Mousepad { get; } = new(); + public static LedMapping Mousepad { get; } = []; /// /// Gets the mapping for headsets. /// - public static LedMapping Headset { get; } = new(); + public static LedMapping Headset { get; } = []; /// /// Gets the mapping for keypads. /// - public static LedMapping Keypad { get; } = new(); + public static LedMapping Keypad { get; } = []; /// /// Gets the mapping for chroma link devices. /// - public static LedMapping ChromaLink { get; } = new(); + public static LedMapping ChromaLink { get; } = []; } diff --git a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs index 105fee90..615e48b1 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs @@ -34,7 +34,7 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe { try { - IntPtr effectParams = CreateEffectParams(dataSet); + nint effectParams = CreateEffectParams(dataSet); Guid effectId = Guid.NewGuid(); CreateEffect(effectParams, ref effectId); @@ -60,7 +60,7 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe /// /// The parameters of the effect. /// The id this effect is created with. - protected abstract void CreateEffect(IntPtr effectParams, ref Guid effectId); + protected abstract void CreateEffect(nint effectParams, ref Guid effectId); /// public override void Reset() @@ -77,7 +77,7 @@ public override void Reset() /// /// The data to be updated. /// An pointing to the effect parameter struct. - protected abstract IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet); + protected abstract nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs index 24cc57be..8ddbce31 100644 --- a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerHeadsetUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS]; @@ -35,14 +35,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _HeadsetCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateHeadsetEffect(_Defines.HEADSET_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateHeadsetEffect(_Defines.HEADSET_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs index b351d5fa..68e0f5f7 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS]; @@ -34,14 +34,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _KeyboardCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateKeyboardEffect(_Defines.KEYBOARD_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeyboardEffect(_Defines.KEYBOARD_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs index 9b6908ae..7e2470e1 100644 --- a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS]; @@ -34,14 +34,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _KeypadCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs index 22295d0a..cbdde12b 100644 --- a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerMouseUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS]; @@ -34,7 +34,7 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _MouseCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; @@ -42,7 +42,7 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateMouseEffect(_Defines.MOUSE_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateMouseEffect(_Defines.MOUSE_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs index 57d912af..8f510e43 100644 --- a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerMousepadUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS]; @@ -34,14 +34,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _MousepadCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateMousepadEffect(_Defines.MOUSEPAD_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateMousepadEffect(_Defines.MOUSEPAD_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Native/_Color.cs b/RGB.NET.Devices.Razer/Native/_Color.cs index 6b792a04..c7d2167f 100644 --- a/RGB.NET.Devices.Razer/Native/_Color.cs +++ b/RGB.NET.Devices.Razer/Native/_Color.cs @@ -10,11 +10,12 @@ namespace RGB.NET.Devices.Razer.Native; // ReSharper disable once InconsistentNaming [StructLayout(LayoutKind.Sequential, Size = sizeof(uint))] -internal struct _Color +[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Native-naming")] +internal struct _Color(byte red, byte green, byte blue) { #region Properties & Fields - public uint Color; + public uint Color = red + ((uint)green << 8) + ((uint)blue << 16); #endregion @@ -23,11 +24,5 @@ internal struct _Color public _Color(Color color) : this(color.GetR(), color.GetG(), color.GetB()) { } - public _Color(byte red, byte green, byte blue) - : this() - { - Color = red + ((uint)green << 8) + ((uint)blue << 16); - } - #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs index a94143db..4b99cc66 100644 --- a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs +++ b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs @@ -16,7 +16,7 @@ internal static class _RazerSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadRazerSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -71,23 +71,23 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadRazerSDK() { - if (_handle == IntPtr.Zero) return; - - _initPointer = IntPtr.Zero; - _unInitPointer = IntPtr.Zero; - _queryDevicePointer = IntPtr.Zero; - _createEffectPointer = IntPtr.Zero; - _createHeadsetEffectPointer = IntPtr.Zero; - _createChromaLinkEffectPointer = IntPtr.Zero; - _createKeyboardEffectPointer = IntPtr.Zero; - _createKeypadEffectPointer = IntPtr.Zero; - _createMouseEffectPointer = IntPtr.Zero; - _createMousepadEffectPointer = IntPtr.Zero; - _setEffectPointer = IntPtr.Zero; - _deleteEffectPointer = IntPtr.Zero; + if (_handle == 0) return; + + _initPointer = 0; + _unInitPointer = 0; + _queryDevicePointer = 0; + _createEffectPointer = 0; + _createHeadsetEffectPointer = 0; + _createChromaLinkEffectPointer = 0; + _createKeyboardEffectPointer = 0; + _createKeypadEffectPointer = 0; + _createMouseEffectPointer = 0; + _createMousepadEffectPointer = 0; + _setEffectPointer = 0; + _deleteEffectPointer = 0; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -96,18 +96,18 @@ internal static void UnloadRazerSDK() #region Pointers - private static IntPtr _initPointer; - private static IntPtr _unInitPointer; - private static IntPtr _queryDevicePointer; - private static IntPtr _createEffectPointer; - private static IntPtr _createHeadsetEffectPointer; - private static IntPtr _createChromaLinkEffectPointer; - private static IntPtr _createKeyboardEffectPointer; - private static IntPtr _createKeypadEffectPointer; - private static IntPtr _createMouseEffectPointer; - private static IntPtr _createMousepadEffectPointer; - private static IntPtr _setEffectPointer; - private static IntPtr _deleteEffectPointer; + private static nint _initPointer; + private static nint _unInitPointer; + private static nint _queryDevicePointer; + private static nint _createEffectPointer; + private static nint _createHeadsetEffectPointer; + private static nint _createChromaLinkEffectPointer; + private static nint _createKeyboardEffectPointer; + private static nint _createKeypadEffectPointer; + private static nint _createMouseEffectPointer; + private static nint _createMousepadEffectPointer; + private static nint _setEffectPointer; + private static nint _deleteEffectPointer; #endregion @@ -128,9 +128,9 @@ internal static unsafe RazerError UnInit() internal static unsafe RazerError QueryDevice(Guid deviceId, out _DeviceInfo deviceInfo) { int structSize = Marshal.SizeOf(typeof(_DeviceInfo)); - IntPtr deviceInfoPtr = Marshal.AllocHGlobal(structSize); + nint deviceInfoPtr = Marshal.AllocHGlobal(structSize); - RazerError error = ((delegate* unmanaged[Cdecl])ThrowIfZero(_queryDevicePointer))(deviceId, deviceInfoPtr); + RazerError error = ((delegate* unmanaged[Cdecl])ThrowIfZero(_queryDevicePointer))(deviceId, deviceInfoPtr); deviceInfo = (_DeviceInfo)Marshal.PtrToStructure(deviceInfoPtr, typeof(_DeviceInfo))!; Marshal.FreeHGlobal(deviceInfoPtr); @@ -138,26 +138,26 @@ internal static unsafe RazerError QueryDevice(Guid deviceId, out _DeviceInfo dev return error; } - internal static unsafe RazerError CreateEffect(Guid deviceId, int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createEffectPointer))(deviceId, effectType, param, ref effectId); + internal static unsafe RazerError CreateEffect(Guid deviceId, int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createEffectPointer))(deviceId, effectType, param, ref effectId); - internal static unsafe RazerError CreateHeadsetEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createHeadsetEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateHeadsetEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createHeadsetEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateChromaLinkEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createChromaLinkEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateChromaLinkEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createChromaLinkEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateKeyboardEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeyboardEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateKeyboardEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeyboardEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateKeypadEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeypadEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateKeypadEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeypadEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateMouseEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMouseEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateMouseEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMouseEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateMousepadEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMousepadEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateMousepadEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMousepadEffectPointer))(effectType, param, ref effectId); internal static unsafe RazerError SetEffect(Guid effectId) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_setEffectPointer))(effectId); @@ -165,9 +165,9 @@ internal static unsafe RazerError SetEffect(Guid effectId) internal static unsafe RazerError DeleteEffect(Guid effectId) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_deleteEffectPointer))(effectId); - private static IntPtr ThrowIfZero(IntPtr ptr) + private static nint ThrowIfZero(nint ptr) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Razer-SDK is not initialized."); + if (ptr == 0) throw new RGBDeviceException("The Razer-SDK is not initialized."); return ptr; } diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 9abc8c82..28bd7da9 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -39,13 +39,13 @@ public static RazerDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { @"%systemroot%\SysWOW64\RzChromaSDK.dll" }; + public static List PossibleX86NativePaths { get; } = [@"%systemroot%\SysWOW64\RzChromaSDK.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { @"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll" }; + public static List PossibleX64NativePaths { get; } = [@"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll"]; /// /// Forces to load the devices represented by the emulator even if they aren't reported to exist. diff --git a/RGB.NET.Devices.SteelSeries/API/Model/Event.cs b/RGB.NET.Devices.SteelSeries/API/Model/Event.cs index 2862e941..c2aa064e 100644 --- a/RGB.NET.Devices.SteelSeries/API/Model/Event.cs +++ b/RGB.NET.Devices.SteelSeries/API/Model/Event.cs @@ -15,7 +15,7 @@ internal sealed class Event // ReSharper disable once CollectionNeverQueried.Global [JsonPropertyName("data")] - public Dictionary Data { get; } = new(); + public Dictionary Data { get; } = []; #endregion diff --git a/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs b/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs index d500a536..f0aff23d 100644 --- a/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs +++ b/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs @@ -1,19 +1,10 @@ namespace RGB.NET.Devices.SteelSeries; -internal sealed class APIName : System.Attribute +internal sealed class APIName(string name) : System.Attribute { #region Properties & Fields - public string Name { get; set; } - - #endregion - - #region Constructors - - public APIName(string name) - { - this.Name = name; - } + public string Name { get; set; } = name; #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs b/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs index aef597b8..df89db97 100644 --- a/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs +++ b/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs @@ -10,8 +10,8 @@ internal static class SteelSeriesEnumExtension #region Properties & Fields // ReSharper disable InconsistentNaming - private static readonly Dictionary _deviceTypeNames = new(); - private static readonly Dictionary _ledIdNames = new(); + private static readonly Dictionary _deviceTypeNames = []; + private static readonly Dictionary _ledIdNames = []; // ReSharper restore InconsistentNaming #endregion diff --git a/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs index 86948692..736e0475 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.SteelSeries; /// /// Represents a steelseries RGB-device. /// -internal interface ISteelSeriesRGBDevice : IRGBDevice -{ } \ No newline at end of file +internal interface ISteelSeriesRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs b/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs index b101ff70..501156e1 100644 --- a/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs +++ b/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs @@ -4,5 +4,5 @@ namespace RGB.NET.Devices.SteelSeries.Helper; internal static class ColorExtensions { - internal static int[] ToIntArray(this Color color) => new int[] { color.GetR(), color.GetG(), color.GetB() }; + internal static int[] ToIntArray(this Color color) => [color.GetR(), color.GetG(), color.GetB()]; } \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs index 2d035ff1..c6b1c009 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs @@ -13,15 +13,15 @@ public sealed class ArduinoWS2812USBUpdateQueue : SerialConnectionUpdateQueue _dataBuffer = new(); + private readonly Dictionary _dataBuffer = []; #endregion @@ -91,7 +91,7 @@ protected override IEnumerable GetCommands(IList<(object key, Color colo for (int i = 1; i <= channelCount; i++) { SerialConnection.ReadTo(Prompt); - byte[] channelLedCountCommand = { (byte)((i << 4) | COUNT_COMMAND[0]) }; + byte[] channelLedCountCommand = [(byte)((i << 4) | COUNT_COMMAND[0])]; SendCommand(channelLedCountCommand); int ledCount = SerialConnection.ReadByte(); if (ledCount > 0) diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs index 131a879f..d4d18f8f 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs @@ -39,7 +39,7 @@ public sealed class BitwizardWS281XDeviceDefinition : IWS281XDeviceDefinition /// /// Gets a list of LED-strips configured on this device. /// - public List<(int pin, int stripLength)> Strips { get; } = new(); + public List<(int pin, int stripLength)> Strips { get; } = []; /// /// Gets or sets the amount of leds controlled by one pin. diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs index a78343c5..38a51f1a 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -23,8 +23,8 @@ public sealed class NodeMCUWS2812USBUpdateQueue : UpdateQueue private HttpClient _httpClient = new(); private UdpClient? _udpClient; - private readonly Dictionary _dataBuffer = new(); - private readonly Dictionary _sequenceNumbers = new(); + private readonly Dictionary _dataBuffer = []; + private readonly Dictionary _sequenceNumbers = []; private readonly Action _sendDataAction; diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index e1500287..109877a2 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -37,7 +37,7 @@ public static WS281XDeviceProvider Instance /// // ReSharper disable once CollectionNeverUpdated.Global // ReSharper disable once ReturnTypeCanBeEnumerable.Global - public List DeviceDefinitions { get; } = new(); + public List DeviceDefinitions { get; } = []; #endregion diff --git a/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs b/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs index 89ab9b5e..c54544b7 100644 --- a/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Wooting.Generic; /// /// Represents a Wooting RGB-device. /// -public interface IWootingRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IWootingRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs index 0258cf5b..cc0018c1 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs @@ -15,7 +15,7 @@ internal static class _WootingSDK { #region Library management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; internal static object SdkLock = new(); /// @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadWootingSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -71,21 +71,21 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadWootingSDK() { - if (_handle == IntPtr.Zero) return; + if (_handle == 0) return; Close(); - _getDeviceInfoPointer = IntPtr.Zero; - _keyboardConnectedPointer = IntPtr.Zero; - _resetPointer = IntPtr.Zero; - _closePointer = IntPtr.Zero; - _arrayUpdateKeyboardPointer = IntPtr.Zero; - _arraySetSinglePointer = IntPtr.Zero; - _getDeviceCountPointer = IntPtr.Zero; - _selectDevicePointer = IntPtr.Zero; + _getDeviceInfoPointer = 0; + _keyboardConnectedPointer = 0; + _resetPointer = 0; + _closePointer = 0; + _arrayUpdateKeyboardPointer = 0; + _arraySetSinglePointer = 0; + _getDeviceCountPointer = 0; + _selectDevicePointer = 0; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -94,18 +94,18 @@ internal static void UnloadWootingSDK() #region Pointers - private static IntPtr _getDeviceInfoPointer; - private static IntPtr _keyboardConnectedPointer; - private static IntPtr _resetPointer; - private static IntPtr _closePointer; - private static IntPtr _arrayUpdateKeyboardPointer; - private static IntPtr _arraySetSinglePointer; - private static IntPtr _getDeviceCountPointer; - private static IntPtr _selectDevicePointer; + private static nint _getDeviceInfoPointer; + private static nint _keyboardConnectedPointer; + private static nint _resetPointer; + private static nint _closePointer; + private static nint _arrayUpdateKeyboardPointer; + private static nint _arraySetSinglePointer; + private static nint _getDeviceCountPointer; + private static nint _selectDevicePointer; #endregion - internal static unsafe IntPtr GetDeviceInfo() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_getDeviceInfoPointer))(); + internal static unsafe nint GetDeviceInfo() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_getDeviceInfoPointer))(); internal static unsafe bool KeyboardConnected() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_keyboardConnectedPointer))(); internal static unsafe bool Reset() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_resetPointer))(); internal static unsafe bool Close() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_closePointer))(); @@ -115,9 +115,9 @@ internal static unsafe bool ArraySetSingle(byte row, byte column, byte red, byte internal static unsafe byte GetDeviceCount() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_getDeviceCountPointer))(); internal static unsafe void SelectDevice(byte index) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_selectDevicePointer))(index); - private static IntPtr ThrowIfZero(IntPtr ptr) + private static nint ThrowIfZero(nint ptr) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Wooting-SDK is not initialized."); + if (ptr == 0) throw new RGBDeviceException("The Wooting-SDK is not initialized."); return ptr; } diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index c92661f9..8b36ff75 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -38,26 +38,26 @@ public static WootingDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. /// The first match will be used. /// - public static List PossibleX86NativePathsWindows { get; } = new() { "x86/wooting-rgb-sdk.dll" }; + public static List PossibleX86NativePathsWindows { get; } = ["x86/wooting-rgb-sdk.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 windows applications. /// The first match will be used. /// - public static List PossibleX64NativePathsWindows { get; } = new() { "x64/wooting-rgb-sdk64.dll" }; + public static List PossibleX64NativePathsWindows { get; } = ["x64/wooting-rgb-sdk64.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 linux applications. /// The first match will be used. /// - public static List PossibleNativePathsLinux { get; } = new() { "x64/libwooting-rgb-sdk.so" }; + public static List PossibleNativePathsLinux { get; } = ["x64/libwooting-rgb-sdk.so"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 MacOS applications. /// The first match will be used. /// // ReSharper disable once InconsistentNaming - public static List PossibleNativePathsMacOS { get; } = new() { "x64/libwooting-rgb-sdk.dylib" }; + public static List PossibleNativePathsMacOS { get; } = ["x64/libwooting-rgb-sdk.dylib"]; #endregion diff --git a/RGB.NET.HID/HIDLoader.cs b/RGB.NET.HID/HIDLoader.cs index b39df671..987618d1 100644 --- a/RGB.NET.HID/HIDLoader.cs +++ b/RGB.NET.HID/HIDLoader.cs @@ -24,7 +24,7 @@ public sealed class HIDLoader : IEnumerable> _deviceDefinitions = new(); + private readonly Dictionary> _deviceDefinitions = []; /// /// Gets the vendor id used for this loader. diff --git a/RGB.NET.Layout/DeviceLayout.cs b/RGB.NET.Layout/DeviceLayout.cs index e33e7609..adf769d8 100644 --- a/RGB.NET.Layout/DeviceLayout.cs +++ b/RGB.NET.Layout/DeviceLayout.cs @@ -92,7 +92,7 @@ public class DeviceLayout : IDeviceLayout /// Normally you should use to access this data. /// [XmlArray("Leds")] - public List InternalLeds { get; set; } = new(); + public List InternalLeds { get; set; } = []; /// /// Gets or sets a list of representing all the of the . diff --git a/RGB.NET.Layout/LayoutExtension.cs b/RGB.NET.Layout/LayoutExtension.cs index 0426e3b7..d336e147 100644 --- a/RGB.NET.Layout/LayoutExtension.cs +++ b/RGB.NET.Layout/LayoutExtension.cs @@ -24,7 +24,7 @@ public static void ApplyTo(this IDeviceLayout layout, IRGBDevice device, bool cr device.Size = new Size(layout.Width, layout.Height); device.DeviceInfo.LayoutMetadata = layout.CustomData; - HashSet ledIds = new(); + HashSet ledIds = []; foreach (ILedLayout layoutLed in layout.Leds) { if (Enum.TryParse(layoutLed.Id, true, out LedId ledId)) @@ -77,13 +77,13 @@ public static void Save(this IDeviceLayout layout, Stream stream) Type[] customTypes; if ((customDataType != null) && (customLedDataType != null)) - customTypes = new[] { customDataType, customLedDataType }; + customTypes = [customDataType, customLedDataType]; else if (customDataType != null) - customTypes = new[] { customDataType }; + customTypes = [customDataType]; else if (customLedDataType != null) - customTypes = new[] { customLedDataType }; + customTypes = [customLedDataType]; else - customTypes = Array.Empty(); + customTypes = []; if (layout is DeviceLayout deviceLayout) { diff --git a/RGB.NET.Presets/Decorators/IGradientDecorator.cs b/RGB.NET.Presets/Decorators/IGradientDecorator.cs index 9373e4ea..75631768 100644 --- a/RGB.NET.Presets/Decorators/IGradientDecorator.cs +++ b/RGB.NET.Presets/Decorators/IGradientDecorator.cs @@ -6,5 +6,4 @@ namespace RGB.NET.Presets.Decorators; /// /// Represents a basic decorator decorating a . /// -public interface IGradientDecorator : IDecorator -{ } \ No newline at end of file +public interface IGradientDecorator : IDecorator; \ No newline at end of file diff --git a/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs b/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs index 50c51429..b8a54af6 100644 --- a/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs +++ b/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs @@ -24,7 +24,7 @@ public abstract class AbstractGradient : AbstractDecoratable /// /// Gets a list of the stops used by this . /// - public ObservableCollection GradientStops { get; } = new(); + public ObservableCollection GradientStops { get; } = []; private bool _wrapGradient; /// diff --git a/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs b/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs index 18fa2521..e756a0b7 100644 --- a/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs +++ b/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs @@ -16,7 +16,7 @@ public sealed class LinearGradient : AbstractGradient #region Properties & Fields private bool _isOrderedGradientListDirty = true; - private readonly List _orderedGradientStops = new(); + private readonly List _orderedGradientStops = []; #endregion diff --git a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs index 322eb5ce..a55592d6 100644 --- a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs +++ b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs @@ -66,7 +66,7 @@ public static int Seed else { _perm = new byte[512]; - Random random = new Random(value); + Random random = new(value); random.NextBytes(_perm); } @@ -172,7 +172,7 @@ private static float Generate(float x, float y) // Add contributions from each corner to get the final noise value. // The result is scaled to return values in the interval [-1,1]. - return 40.0f * (n0 + n1 + n2); // TODO: The scale factor is preliminary! + return 40.0f * (n0 + n1 + n2); } @@ -276,12 +276,13 @@ private static float Generate(float x, float y, float z) // Add contributions from each corner to get the final noise value. // The result is scaled to stay just inside [-1,1] - return 32.0f * (n0 + n1 + n2 + n3); // TODO: The scale factor is preliminary! + return 32.0f * (n0 + n1 + n2 + n3); } private static byte[] _perm; - private static readonly byte[] PermOriginal = { + private static readonly byte[] PermOriginal = + [ 151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, @@ -308,7 +309,7 @@ private static float Generate(float x, float y, float z) 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 - }; + ]; private static int FastFloor(float x) {