diff --git a/Megumin.Explosion/Megumin/Class/Multiple.cs b/Megumin.Explosion/Megumin/Class/Multiple.cs index e7f0c76..968051b 100644 --- a/Megumin.Explosion/Megumin/Class/Multiple.cs +++ b/Megumin.Explosion/Megumin/Class/Multiple.cs @@ -11,7 +11,10 @@ namespace Megumin /// public abstract partial class Multiple : EqualComparer, IMultiple { - protected readonly Dictionary ElementDic = new Dictionary(); + /// + /// 所有构成项的字典,如果没有特殊需求不要再外部更改,使用方法。 + /// + public readonly Dictionary ElementDic = new(); public event OnChanged ValueChanged; public event OnChanged<(K Key, V Value)> ValueChangedKV; public event OnChanged<(K Key, V Value)> KeyOrValueChanged; @@ -160,6 +163,14 @@ public virtual V RemoveAll(int raiseEvent = 0) return Current; } + public V RemoveAll(Func, bool> predicate, int raiseEvent = 0) + { + ElementDic.RemoveAll(predicate); + ElementDic[DefaultKey] = DefaultValue; + ApplyValue(raiseEvent); + return Current; + } + /// /// 返回当前值 /// diff --git a/Megumin.Explosion/Megumin/Interface/IMultiple.cs b/Megumin.Explosion/Megumin/Interface/IMultiple.cs index 9ae6d3e..8de6415 100644 --- a/Megumin.Explosion/Megumin/Interface/IMultiple.cs +++ b/Megumin.Explosion/Megumin/Interface/IMultiple.cs @@ -56,6 +56,14 @@ public interface IMultiple /// V RemoveAll(int raiseEvent = 0); + /// + /// 取消除默认值以外的所有符合条件的构成项 + /// + /// + /// Ignore = -1,Force:101, + /// + V RemoveAll(Func, bool> predicate, int raiseEvent = 0); + /// /// 在控制项没有变动的情况下,触发ApplyValue,尝试触发事件。 ///