public static bool TryGetValue <TObject, TKey>(this IReadOnlyCache <TObject, TKey> cache, TKey key, [MaybeNullWhen(false)] out TObject value) { // ToDo // Improve to not double query if (cache.ContainsKey(key)) { value = cache[key]; return(true); } value = default; return(false); }
public static IEnumerable <KeyValuePair <K, R> > SelectAgainst <K, V, R>( this IReadOnlyCache <V, K> lhs, IReadOnlyCache <V, K> rhs, Func <K, V, V, R> selector, out bool equal) { var ret = new List <KeyValuePair <K, R> >(); equal = lhs.Count == rhs.Count; foreach (var item in lhs) { if (!rhs.ContainsKey(item.Key)) { equal = false; continue; } ret.Add( new KeyValuePair <K, R>( item.Key, selector(item.Key, item.Value, rhs[item.Key]))); } return(ret); }