mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
namespace RGB.NET.Core
|
|
{
|
|
/// <inheritdoc />
|
|
public abstract class AbstractDecoratable<T> : AbstractBindable, IDecoratable<T>
|
|
where T : IDecorator
|
|
{
|
|
#region Properties & Fields
|
|
|
|
private List<T> _decorators = new List<T>();
|
|
/// <summary>
|
|
/// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>.
|
|
/// </summary>
|
|
protected IReadOnlyCollection<T> Decorators => new ReadOnlyCollection<T>(_decorators);
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <inheritdoc />
|
|
public void AddDecorator(T decorator)
|
|
{
|
|
_decorators.Add(decorator);
|
|
_decorators = _decorators.OrderByDescending(x => x.Order).ToList();
|
|
|
|
decorator.OnAttached(this);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void RemoveDecorator(T decorator)
|
|
{
|
|
_decorators.Remove(decorator);
|
|
|
|
decorator.OnDetached(this);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|