// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global using CUE.NET.Devices.Generic; using CUE.NET.Devices.Generic.Enums; namespace CUE.NET.Groups.Extensions { /// /// Offers some extensions and helper-methods for ledgroup related things. /// public static class LedGroupExtension { /// /// Converts the given to a . /// /// The to convert. /// The converted . public static ListLedGroup ToListLedGroup(this AbstractLedGroup ledGroup) { ListLedGroup listLedGroup = ledGroup as ListLedGroup; // ReSharper disable once InvertIf if (listLedGroup == null) { bool wasAttached = ledGroup.Detach(); listLedGroup = new ListLedGroup(ledGroup.Device, wasAttached, ledGroup.GetLeds()) { Brush = ledGroup.Brush }; } return listLedGroup; } /// /// Returns a new which contains all LEDs from the given ledgroup excluding the specified ones. /// /// The base ledgroup. /// The ids of the LEDs to exclude. /// The new . public static ListLedGroup Exclude(this AbstractLedGroup ledGroup, params CorsairLedId[] ledIds) { ListLedGroup listLedGroup = ledGroup.ToListLedGroup(); foreach (CorsairLedId ledId in ledIds) listLedGroup.RemoveLed(ledId); return listLedGroup; } /// /// Returns a new which contains all LEDs from the given ledgroup excluding the specified ones. /// /// The base ledgroup. /// The LEDs to exclude. /// The new . public static ListLedGroup Exclude(this AbstractLedGroup ledGroup, params CorsairLed[] ledIds) { ListLedGroup listLedGroup = ledGroup.ToListLedGroup(); foreach (CorsairLed led in ledIds) listLedGroup.RemoveLed(led); return listLedGroup; } // ReSharper disable once UnusedMethodReturnValue.Global /// /// Attaches the given ledgroup to the device. /// /// The ledgroup to attach. /// true if the ledgroup could be attached; otherwise, false. public static bool Attach(this AbstractLedGroup ledGroup) { return ledGroup.Device?.AttachLedGroup(ledGroup) ?? false; } /// /// Detaches the given ledgroup from the device. /// /// The ledgroup to attach. /// true if the ledgroup could be detached; otherwise, false. public static bool Detach(this AbstractLedGroup ledGroup) { return ledGroup.Device?.DetachLedGroup(ledGroup) ?? false; } } }