Skip to content

Commit

Permalink
Make Dictionary more honest (convert to class)
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Aug 20, 2020
1 parent 903a07f commit 861585c
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions MoreLinq/Collections/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ namespace MoreLinq.Collections

// Add members if and when needed to keep coverage.

struct Dictionary<TKey, TValue>
sealed class Dictionary<TKey, TValue>
{
readonly System.Collections.Generic.Dictionary<TKey, TValue> _dict;
(bool, TValue) _null;

public Dictionary(IEqualityComparer<TKey> comparer) : this()
public Dictionary(IEqualityComparer<TKey> comparer)
{
_dict = new System.Collections.Generic.Dictionary<TKey, TValue>(comparer);
_null = default;
Expand All @@ -44,8 +44,6 @@ public TValue this[TKey key]
{
set
{
DefaultGuard();

if (key is null)
_null = (true, value);
else
Expand All @@ -55,8 +53,6 @@ public TValue this[TKey key]

public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
{
DefaultGuard();

if (key is null)
{
switch (_null)
Expand All @@ -72,11 +68,5 @@ public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)

return _dict.TryGetValue(key, out value);
}

void DefaultGuard()
{
if (_dict is null)
throw new InvalidOperationException();
}
}
}

0 comments on commit 861585c

Please sign in to comment.