mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 20:17:15 +00:00
Extension method for inverting a dictionary
This commit is contained in:
parent
d4b0fc76cc
commit
b0aa48803b
1 changed files with 16 additions and 0 deletions
|
|
@ -386,5 +386,21 @@ namespace ICD.Common.Utils.Extensions
|
|||
|
||||
return extends.OrderByKey().Select(kvp => kvp.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an inverse mapping of TValue -> TKey.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static Dictionary<TValue, TKey> ToInverse<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
return extends.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue