mirror of
https://github.com/Prowlarr/Prowlarr
synced 2025-12-06 08:34:28 +01:00
Originally called project metis, this feature allows you to do a lot of cool stuff, such as upgrading to a x265 encode, downloading releases with multiple languages, etc. Check out the wiki page at: https://github.com/Radarr/Radarr/wiki/Custom-Formats to learn more! Note: This feature is currently in "beta" and will get more tags and features in the future. Please let me know, if you have any issues and I hope this will allow for a lot of customization!
46 lines
1.9 KiB
C#
46 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace NzbDrone.Common.Extensions
|
|
{
|
|
public static class DictionaryExtensions
|
|
{
|
|
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue))
|
|
{
|
|
TValue value;
|
|
return dictionary.TryGetValue(key, out value) ? value : defaultValue;
|
|
}
|
|
|
|
public static Dictionary<T1, T2> Merge<T1, T2>(this Dictionary<T1, T2> first, Dictionary<T1, T2> second)
|
|
{
|
|
if (first == null) throw new ArgumentNullException("first");
|
|
if (second == null) throw new ArgumentNullException("second");
|
|
|
|
var merged = new Dictionary<T1, T2>();
|
|
first.ToList().ForEach(kv => merged[kv.Key] = kv.Value);
|
|
second.ToList().ForEach(kv => merged[kv.Key] = kv.Value);
|
|
|
|
return merged;
|
|
}
|
|
|
|
public static void Add<TKey, TValue>(this ICollection<KeyValuePair<TKey, TValue>> collection, TKey key, TValue value)
|
|
{
|
|
collection.Add(new KeyValuePair<TKey, TValue>(key, value));
|
|
}
|
|
|
|
public static IDictionary<TNewKey, TNewValue> SelectDictionary<TKey, TValue, TNewKey, TNewValue>(this IDictionary<TKey, TValue> dictionary,
|
|
Func<KeyValuePair<TKey, TValue>, ValueTuple<TNewKey, TNewValue>> selection)
|
|
{
|
|
return dictionary.Select(selection).ToDictionary(t => t.Item1, t => t.Item2);
|
|
}
|
|
|
|
public static IDictionary<TNewKey, TNewValue> SelectDictionary<TKey, TValue, TNewKey, TNewValue>(
|
|
this IDictionary<TKey, TValue> dictionary,
|
|
Func<KeyValuePair<TKey, TValue>, TNewKey> keySelector,
|
|
Func<KeyValuePair<TKey, TValue>, TNewValue> valueSelector)
|
|
{
|
|
return dictionary.SelectDictionary(p => { return (keySelector(p), valueSelector(p)); });
|
|
}
|
|
}
|
|
}
|