using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace RGB.NET.Core { /// /// public abstract class AbstractDecoratable : AbstractBindable, IDecoratable where T : IDecorator { #region Properties & Fields private List _decorators = new List(); /// /// Gets a readonly-list of all attached to this . /// protected IReadOnlyCollection Decorators => new ReadOnlyCollection(_decorators); #endregion #region Methods /// public void AddDecorator(T decorator) { _decorators.Add(decorator); _decorators = _decorators.OrderByDescending(x => x.Order).ToList(); decorator.OnAttached(this); } /// public void RemoveDecorator(T decorator) { _decorators.Remove(decorator); decorator.OnDetached(this); } /// public void RemoveAllDecorators() { foreach (T decorator in Decorators.ToList()) RemoveDecorator(decorator); } #endregion } }