// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global namespace RGB.NET.Core; /// /// Offers some extensions and helper-methods for related things. /// public static class LedGroupExtension { /// /// Converts the specified to a . /// /// The to convert. /// The converted . public static ListLedGroup ToListLedGroup(this ILedGroup ledGroup) { // ReSharper disable once InvertIf if (ledGroup is not ListLedGroup listLedGroup) { if (ledGroup.IsAttached) ledGroup.Detach(); listLedGroup = new ListLedGroup(ledGroup.Surface, ledGroup) { Brush = ledGroup.Brush, ZIndex = ledGroup.ZIndex }; } return listLedGroup; } /// /// Returns a new which contains all from the specified excluding the specified ones. /// /// The base . /// The to exclude. /// The new . public static ListLedGroup Exclude(this ILedGroup ledGroup, params Led[] ledIds) { ListLedGroup listLedGroup = ledGroup.ToListLedGroup(); foreach (Led led in ledIds) listLedGroup.RemoveLed(led); return listLedGroup; } // ReSharper disable once UnusedMethodReturnValue.Global /// /// Attaches the specified to the . /// /// The to attach. /// The to attach this group to. /// true if the could be attached; otherwise, false. public static bool Attach(this ILedGroup ledGroup, RGBSurface surface) => surface.Attach(ledGroup); /// /// Detaches the specified from the . /// /// The to attach. /// true if the could be detached; otherwise, false. public static bool Detach(this ILedGroup ledGroup) => ledGroup.Surface?.Detach(ledGroup) ?? false; }