diff --git a/RGB.NET.Core/Effects/AbstractEffectTarget.cs b/RGB.NET.Core/Effects/AbstractEffectTarget.cs index 45d49e8..b08cefb 100644 --- a/RGB.NET.Core/Effects/AbstractEffectTarget.cs +++ b/RGB.NET.Core/Effects/AbstractEffectTarget.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using RGB.NET.Core.Exceptions; @@ -24,7 +25,10 @@ namespace RGB.NET.Core /// /// Gets all attached to this . /// - protected IList> Effects => EffectTimes.Select(x => x.Effect).Cast>().ToList(); + protected IList> InternalEffects => EffectTimes.Select(x => x.Effect).Cast>().ToList(); + + /// + public IEnumerable> Effects => new ReadOnlyCollection>(InternalEffects); /// /// Gets the strongly-typed target used for the . @@ -40,7 +44,7 @@ namespace RGB.NET.Core /// public virtual void UpdateEffects() { - lock (Effects) + lock (InternalEffects) { for (int i = EffectTimes.Count - 1; i >= 0; i--) { @@ -96,6 +100,19 @@ namespace RGB.NET.Core EffectTimes.Remove(effectTimeToRemove); } + /// + public bool HasEffect(IEffect effect) + { + return InternalEffects.Contains(effect); + } + + /// + public bool HasEffect() + where TEffect : IEffect + { + return InternalEffects.Any(x => x.GetType() == typeof(TEffect)); + } + #endregion } } diff --git a/RGB.NET.Core/Effects/IEffectTarget.cs b/RGB.NET.Core/Effects/IEffectTarget.cs index fa62948..777d513 100644 --- a/RGB.NET.Core/Effects/IEffectTarget.cs +++ b/RGB.NET.Core/Effects/IEffectTarget.cs @@ -1,14 +1,25 @@ // ReSharper disable UnusedMember.Global +using System.Collections.Generic; + namespace RGB.NET.Core { /// /// Represents a basic effect-target. /// /// The type this target represents. - public interface IEffectTarget + public interface IEffectTarget where T : IEffectTarget { + #region Properties & Fields + + /// + /// Gets a readonly collection of all of this . + /// + IEnumerable> Effects { get; } + + #endregion + #region Methods /// @@ -28,6 +39,20 @@ namespace RGB.NET.Core /// The to remove. void RemoveEffect(IEffect effect); + /// + /// Checks if the is added to this . + /// + /// The to check. + /// true if the is added to this .; otherwise, false. + bool HasEffect(IEffect effect); + + /// + /// Checks if any of the provided generic type is added to this . + /// + /// The generic type of the to check. + /// true if any of the provided type is added to this .; otherwise, false. + bool HasEffect() where TEffect : IEffect; + #endregion } }