// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Groups
{
///
/// 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))
{
bool wasAttached = ledGroup.Detach();
listLedGroup = new ListLedGroup(wasAttached, 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.Instance.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.Instance.DetachLedGroup(ledGroup);
}
}