DictionaryExtensions.cs 715 B

12345678910111213141516171819
  1. using System.Collections.Generic;
  2. namespace TeamAAS.FlowEngine
  3. {
  4. /// <summary>
  5. /// 集合扩展方法。
  6. /// 背景:DeleteIfExistsKey 原先来自 HandyControls fork 的 HandyControl.Tools.Extension,
  7. /// 切换到官方 HandyControl 后由本文件补齐等价实现,避免依赖 fork 包。
  8. /// </summary>
  9. public static class DictionaryExtensions
  10. {
  11. /// <summary>存在则删除指定键,不存在则静默跳过</summary>
  12. public static bool DeleteIfExistsKey<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key)
  13. {
  14. if (dictionary == null || key == null) return false;
  15. return dictionary.Remove(key);
  16. }
  17. }
  18. }