Skip to content

Commit

Permalink
多重控制删除指定元素
Browse files Browse the repository at this point in the history
  • Loading branch information
KumoKyaku committed Jan 9, 2024
1 parent c885b66 commit ab8ee89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Megumin.Explosion/Megumin/Class/Multiple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace Megumin
/// <typeparam name="V"></typeparam>
public abstract partial class Multiple<K, V> : EqualComparer<V>, IMultiple<K, V>
{
protected readonly Dictionary<K, V> ElementDic = new Dictionary<K, V>();
/// <summary>
/// 所有构成项的字典,如果没有特殊需求不要再外部更改,使用方法。
/// </summary>
public readonly Dictionary<K, V> ElementDic = new();
public event OnChanged<V> ValueChanged;
public event OnChanged<(K Key, V Value)> ValueChangedKV;
public event OnChanged<(K Key, V Value)> KeyOrValueChanged;
Expand Down Expand Up @@ -160,6 +163,14 @@ public virtual V RemoveAll(int raiseEvent = 0)
return Current;
}

public V RemoveAll(Func<KeyValuePair<K, V>, bool> predicate, int raiseEvent = 0)
{
ElementDic.RemoveAll(predicate);
ElementDic[DefaultKey] = DefaultValue;
ApplyValue(raiseEvent);
return Current;
}

/// <summary>
/// 返回当前值
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Megumin.Explosion/Megumin/Interface/IMultiple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public interface IMultiple<K, V>
/// <returns></returns>
V RemoveAll(int raiseEvent = 0);

/// <summary>
/// 取消除默认值以外的所有符合条件的构成项
/// </summary>
/// <param name="predicate"></param>
/// <param name="raiseEvent">Ignore = -1,Force:101, <seealso cref="RaiseEvent"/></param>
/// <returns></returns>
V RemoveAll(Func<KeyValuePair<K, V>, bool> predicate, int raiseEvent = 0);

/// <summary>
/// 在控制项没有变动的情况下,触发ApplyValue,尝试触发事件。
/// </summary>
Expand Down

0 comments on commit ab8ee89

Please sign in to comment.