頻繁なチェックをカプセル化するためにMultiValueDictionaryの拡張メソッドをContainsKey
作成していますが、空のIReadOnlyCollection
?.
私がこれまで使ってきたnew List<TValue>(0).AsReadOnly()
のIEnumerable
はEnumerable.Empty
public static IReadOnlyCollection<TValue> GetValuesOrEmpty<TKey, TValue>(this MultiValueDictionary<TKey, TValue> multiValueDictionary, TKey key)
{
IReadOnlyCollection<TValue> values;
return !multiValueDictionary.TryGetValue(key, out values) ? new List<TValue>(0).AsReadOnly() : values;
}