mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-13 20:47:24 +00:00
Extension method for removing a sequence of keys from a dict
This commit is contained in:
parent
3eb4fa9e92
commit
232a52d608
1 changed files with 17 additions and 4 deletions
|
|
@ -7,6 +7,22 @@ namespace ICD.Common.Utils.Extensions
|
||||||
{
|
{
|
||||||
public static class DictionaryExtensions
|
public static class DictionaryExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all of the given keys from the dictionary.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
/// <typeparam name="TValue"></typeparam>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <param name="keys"></param>
|
||||||
|
public static void RemoveAll<TKey, TValue>(this IDictionary<TKey, TValue> extends, IEnumerable<TKey> keys)
|
||||||
|
{
|
||||||
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
|
foreach (TKey key in keys)
|
||||||
|
extends.Remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the first key with a value matching the given value.
|
/// Removes the first key with a value matching the given value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -22,10 +38,7 @@ namespace ICD.Common.Utils.Extensions
|
||||||
throw new ArgumentNullException("extends");
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
TKey key;
|
TKey key;
|
||||||
if (!extends.TryGetKey(value, out key))
|
return extends.TryGetKey(value, out key) && extends.Remove(key);
|
||||||
return false;
|
|
||||||
|
|
||||||
return extends.Remove(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue