// 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 given to a .
///
/// The to convert.
/// The converted .
public static ListLedGroup ToListLedGroup(this ILedGroup ledGroup)
{
// ReSharper disable once InvertIf
if (!(ledGroup is ListLedGroup listLedGroup))
{
if (ledGroup.Surface != null)
ledGroup.Detach(ledGroup.Surface);
listLedGroup = new ListLedGroup(ledGroup.Surface, ledGroup.GetLeds()) { Brush = ledGroup.Brush };
}
return listLedGroup;
}
///
/// Returns a new which contains all from the given 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 given to the .
///
/// The to attach.
/// true if the could be attached; otherwise, false.
public static bool Attach(this ILedGroup ledGroup, RGBSurface surface) => surface.AttachLedGroup(ledGroup);
///
/// Detaches the given from the .
///
/// The to attach.
/// true if the could be detached; otherwise, false.
public static bool Detach(this ILedGroup ledGroup, RGBSurface surface) => surface.DetachLedGroup(ledGroup);
}
}