Skip to content

Commit

Permalink
fixup! Implement ImmutableSegmentedDictionary<TKey, TValue>.ValueBuil…
Browse files Browse the repository at this point in the history
…der for internal use
  • Loading branch information
sharwell committed Feb 29, 2024
1 parent 695a6d3 commit 7fea688
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public readonly bool ContainsKey(TKey key)
public readonly bool ContainsValue(TValue value)
=> ReadOnlyDictionary.ContainsValue(value);

public readonly Enumerator GetEnumerator()
=> new(ReadOnlyDictionary, Enumerator.ReturnType.KeyValuePair);
public Enumerator GetEnumerator()
=> new(GetOrCreateMutableDictionary(), Enumerator.ReturnType.KeyValuePair);

public readonly TValue? GetValueOrDefault(TKey key)
{
Expand Down Expand Up @@ -202,7 +202,9 @@ public void RemoveRange(IEnumerable<TKey> keys)
}
}

public readonly bool TryGetKey(TKey equalKey, out TKey actualKey)
#pragma warning disable IDE0251 // Make member 'readonly' (false positive: https://github.com/dotnet/roslyn/issues/72335)
public bool TryGetKey(TKey equalKey, out TKey actualKey)
#pragma warning restore IDE0251 // Make member 'readonly'
{
foreach (var pair in this)
{
Expand Down Expand Up @@ -232,20 +234,20 @@ public ImmutableSegmentedDictionary<TKey, TValue> ToImmutable()
readonly void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
=> ((ICollection<KeyValuePair<TKey, TValue>>)ReadOnlyDictionary).CopyTo(array, arrayIndex);

readonly IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
=> new Enumerator(ReadOnlyDictionary, Enumerator.ReturnType.KeyValuePair);
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
=> new Enumerator(GetOrCreateMutableDictionary(), Enumerator.ReturnType.KeyValuePair);

readonly IEnumerator IEnumerable.GetEnumerator()
=> new Enumerator(ReadOnlyDictionary, Enumerator.ReturnType.KeyValuePair);
IEnumerator IEnumerable.GetEnumerator()
=> new Enumerator(GetOrCreateMutableDictionary(), Enumerator.ReturnType.KeyValuePair);

readonly bool IDictionary.Contains(object key)
=> ((IDictionary)ReadOnlyDictionary).Contains(key);

void IDictionary.Add(object key, object? value)
=> ((IDictionary)GetOrCreateMutableDictionary()).Add(key, value);

readonly IDictionaryEnumerator IDictionary.GetEnumerator()
=> new Enumerator(ReadOnlyDictionary, Enumerator.ReturnType.DictionaryEntry);
IDictionaryEnumerator IDictionary.GetEnumerator()
=> new Enumerator(GetOrCreateMutableDictionary(), Enumerator.ReturnType.DictionaryEntry);

void IDictionary.Remove(object key)
=> ((IDictionary)GetOrCreateMutableDictionary()).Remove(key);
Expand Down

0 comments on commit 7fea688

Please sign in to comment.