From efe77cedbc2b80b4dbeca3b1ae1ea4720cbac4b7 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 14 Jan 2018 11:57:45 +0100 Subject: [PATCH] Small refactorings to unify code styling --- RGB.NET.Core/Positioning/Rectangle.cs | 5 +- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 1 + .../CoolerMasterDeviceProvider.cs | 1 + .../Keyboard/CoolerMasterKeyboardRGBDevice.cs | 6 +- .../CoolerMasterKeyboardRGBDeviceInfo.cs | 2 +- .../Native/_CoolerMasterColorMatrix.cs | 22 ++++++ .../Native/_CoolerMasterKeyColor.cs | 30 +++++++++ .../Native/_CoolerMasterSDK.cs | 67 +++---------------- .../RGB.NET.Devices.CoolerMaster.csproj | 2 + .../Native/_LogitechGSDK.cs | 45 +++---------- 10 files changed, 80 insertions(+), 101 deletions(-) create mode 100644 RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterColorMatrix.cs create mode 100644 RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterKeyColor.cs diff --git a/RGB.NET.Core/Positioning/Rectangle.cs b/RGB.NET.Core/Positioning/Rectangle.cs index 2f55af2..ede55c3 100644 --- a/RGB.NET.Core/Positioning/Rectangle.cs +++ b/RGB.NET.Core/Positioning/Rectangle.cs @@ -335,8 +335,7 @@ namespace RGB.NET.Core /// true if is a equivalent to this ; otherwise, false. public override bool Equals(object obj) { - Rectangle compareRect = obj as Rectangle; - if (ReferenceEquals(compareRect, null)) + if (!(obj is Rectangle compareRect)) return false; if (ReferenceEquals(this, compareRect)) @@ -372,7 +371,7 @@ namespace RGB.NET.Core /// The first to compare. /// The second to compare. /// true if and are equal; otherwise, false. - public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) => ReferenceEquals(rectangle1, null) ? ReferenceEquals(rectangle2, null) : rectangle1.Equals(rectangle2); + public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) => rectangle1?.Equals(rectangle2) ?? ReferenceEquals(rectangle2, null); /// /// Returns a value that indicates whether two specified are equal. diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 7cd9ec7..3f8cae2 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -60,6 +60,7 @@ namespace RGB.NET.Devices.Asus /// /// Gets or sets a function to get the culture for a specific device. /// + // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture; #endregion diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 6b19228..23bae1d 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -60,6 +60,7 @@ namespace RGB.NET.Devices.CoolerMaster /// /// Gets or sets a function to get the culture for a specific device. /// + // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture; #endregion diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs index 8c91fea..558ba80 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs @@ -34,15 +34,15 @@ namespace RGB.NET.Devices.CoolerMaster if (leds.Count > 0) { // 6 by 22 seems hard-coded but it's what the CM SDK expects regardless of keyboard size - _CoolerMasterSDK.COLOR_MATRIX matrix = new _CoolerMasterSDK.COLOR_MATRIX { KeyColor = new _CoolerMasterSDK.KEY_COLOR[6, 22] }; + _CoolerMasterColorMatrix colorMatrix = new _CoolerMasterColorMatrix { KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS] }; foreach (Led led in leds) { (int row, int column) = ((int, int))led.CustomData; - matrix.KeyColor[row, column] = new _CoolerMasterSDK.KEY_COLOR(led.Color.R, led.Color.G, led.Color.B); + colorMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(led.Color.R, led.Color.G, led.Color.B); } _CoolerMasterSDK.SetControlDevice(DeviceInfo.DeviceIndex); - _CoolerMasterSDK.SetAllLedColor(matrix); + _CoolerMasterSDK.SetAllLedColor(colorMatrix); _CoolerMasterSDK.RefreshLed(false); } } diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs index 3d4014d..e3017a4 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs @@ -15,7 +15,7 @@ namespace RGB.NET.Devices.CoolerMaster /// /// Gets the of the . /// - public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; private set; } + public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; } /// /// Gets the of the . diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterColorMatrix.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterColorMatrix.cs new file mode 100644 index 0000000..c30f706 --- /dev/null +++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterColorMatrix.cs @@ -0,0 +1,22 @@ +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CoolerMaster.Native +{ + // ReSharper disable once InconsistentNaming + internal struct _CoolerMasterColorMatrix + { + #region Constants + + internal const int ROWS = 6; + internal const int COLUMNS = 22; + + #endregion + + #region Properties & Fields + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = ROWS * COLUMNS)] + public _CoolerMasterKeyColor[,] KeyColor; + + #endregion + } +} diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterKeyColor.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterKeyColor.cs new file mode 100644 index 0000000..b8e26eb --- /dev/null +++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterKeyColor.cs @@ -0,0 +1,30 @@ +// ReSharper disable UnusedMethodReturnValue.Global +// ReSharper disable UnusedMember.Global +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable NotAccessedField.Global + +namespace RGB.NET.Devices.CoolerMaster.Native +{ + // ReSharper disable once InconsistentNaming + internal struct _CoolerMasterKeyColor + { + #region Properties & Fields + + public byte R; + public byte G; + public byte B; + + #endregion + + #region Constructors + + internal _CoolerMasterKeyColor(byte r, byte g, byte b) + { + this.R = r; + this.G = g; + this.B = b; + } + + #endregion + } +} diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs index aac65d4..1b08f60 100644 --- a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs +++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs @@ -74,31 +74,6 @@ namespace RGB.NET.Devices.CoolerMaster.Native #region SDK-METHODS - #region Structs - - // ReSharper disable InconsistentNaming - internal struct KEY_COLOR - { - public byte r; - public byte g; - public byte b; - - public KEY_COLOR(byte colR, byte colG, byte colB) - { - r = colR; - g = colG; - b = colB; - } - } - - internal struct COLOR_MATRIX - { - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 132)] public KEY_COLOR[,] KeyColor; - } - // ReSharper restore InconsistentNaming - - #endregion - #region Pointers private static GetSDKVersionPointer _getSDKVersionPointer; @@ -141,7 +116,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native [UnmanagedFunctionPointer(CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - private delegate bool SetAllLedColorPointer(COLOR_MATRIX colorMatrix); + private delegate bool SetAllLedColorPointer(_CoolerMasterColorMatrix colorMatrix); #endregion @@ -150,66 +125,42 @@ namespace RGB.NET.Devices.CoolerMaster.Native /// /// CM-SDK: Get SDK Dll's Version. /// - internal static int GetSDKVersion() - { - return _getSDKVersionPointer(); - } + internal static int GetSDKVersion() => _getSDKVersionPointer(); /// /// CM-SDK: set operating device /// - internal static void SetControlDevice(CoolerMasterDevicesIndexes devicesIndexes) - { - _setControlDevicenPointer(devicesIndexes); - } + internal static void SetControlDevice(CoolerMasterDevicesIndexes devicesIndexes) => _setControlDevicenPointer(devicesIndexes); /// /// CM-SDK: verify if the deviced is plugged in /// - internal static bool IsDevicePlugged() - { - return _isDevicePlugPointer(); - } + internal static bool IsDevicePlugged() => _isDevicePlugPointer(); /// /// CM-SDK: Obtain current device layout /// - internal static CoolerMasterPhysicalKeyboardLayout GetDeviceLayout() - { - return _getDeviceLayoutPointer(); - } + internal static CoolerMasterPhysicalKeyboardLayout GetDeviceLayout() => _getDeviceLayoutPointer(); /// /// CM-SDK: set control over device’s LED /// - internal static bool EnableLedControl(bool value) - { - return _enableLedControlPointer(value); - } + internal static bool EnableLedControl(bool value) => _enableLedControlPointer(value); /// /// CM-SDK: Print out the lights setting from Buffer to LED /// - internal static bool RefreshLed(bool autoRefresh) - { - return _refreshLedPointer(autoRefresh); - } + internal static bool RefreshLed(bool autoRefresh) => _refreshLedPointer(autoRefresh); /// /// CM-SDK: Set single Key LED color /// - internal static bool SetLedColor(int row, int column, byte r, byte g, byte b) - { - return _setLedColorPointer(row, column, r, g, b); - } + internal static bool SetLedColor(int row, int column, byte r, byte g, byte b) => _setLedColorPointer(row, column, r, g, b); /// /// CM-SDK: Set Keyboard "every LED" color /// - internal static bool SetAllLedColor(COLOR_MATRIX colorMatrix) - { - return _setAllLedColorPointer(colorMatrix); - } + internal static bool SetAllLedColor(_CoolerMasterColorMatrix colorMatrix) => _setAllLedColorPointer(colorMatrix); // ReSharper restore EventExceptionNotDocumented diff --git a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj index b31ad0f..7ae409d 100644 --- a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj +++ b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj @@ -60,7 +60,9 @@ + + diff --git a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs index d3c46f4..c924515 100644 --- a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs +++ b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs @@ -125,20 +125,11 @@ namespace RGB.NET.Devices.Logitech.Native // ReSharper disable EventExceptionNotDocumented - internal static bool LogiLedInit() - { - return _logiLedInitPointer(); - } + internal static bool LogiLedInit() => _logiLedInitPointer(); - internal static void LogiLedShutdown() - { - _logiLedShutdownPointer(); - } + internal static void LogiLedShutdown() => _logiLedShutdownPointer(); - internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) - { - return _logiLedSetTargetDevicePointer((int)targetDevice); - } + internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => _logiLedSetTargetDevicePointer((int)targetDevice); internal static string LogiLedGetSdkVersion() { @@ -150,36 +141,18 @@ namespace RGB.NET.Devices.Logitech.Native return $"{major}.{minor}.{build}"; } - internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) - { - return _logiLedGetSdkVersionPointer(ref majorNum, ref minorNum, ref buildNum); - } + internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) => _logiLedGetSdkVersionPointer(ref majorNum, ref minorNum, ref buildNum); - internal static bool LogiLedSaveCurrentLighting() - { - return _lgiLedSaveCurrentLightingPointer(); - } + internal static bool LogiLedSaveCurrentLighting() => _lgiLedSaveCurrentLightingPointer(); - internal static bool LogiLedRestoreLighting() - { - return _logiLedRestoreLightingPointer(); - } + internal static bool LogiLedRestoreLighting() => _logiLedRestoreLightingPointer(); - internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) - { - return _logiLedSetLightingPointer(redPercentage, greenPercentage, bluePercentage); - } + internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) => _logiLedSetLightingPointer(redPercentage, greenPercentage, bluePercentage); internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode, - int redPercentage, int greenPercentage, int bluePercentage) - { - return _logiLedSetLightingForKeyWithKeyNamePointer(keyCode, redPercentage, greenPercentage, bluePercentage); - } + int redPercentage, int greenPercentage, int bluePercentage) => _logiLedSetLightingForKeyWithKeyNamePointer(keyCode, redPercentage, greenPercentage, bluePercentage); - internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) - { - return _logiLedSetLightingFromBitmapPointer(bitmap); - } + internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => _logiLedSetLightingFromBitmapPointer(bitmap); // ReSharper restore EventExceptionNotDocumented