|
|
@ -35,7 +35,9 @@ namespace System.Runtime.CompilerServices |
|
|
|
} |
|
|
|
|
|
|
|
public void Add(TKey key, TValue value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (key == null) |
|
|
|
throw new ArgumentException("Null key", nameof(key)); |
|
|
|
lock (_lock) |
|
|
|
items.Add(WeakRef(key), value); |
|
|
|
} |
|
|
@ -73,8 +75,13 @@ namespace System.Runtime.CompilerServices |
|
|
|
public TValue GetOrCreateValue(TKey key) |
|
|
|
=> GetValue(key, k => Activator.CreateInstance<TValue>()); |
|
|
|
|
|
|
|
public bool Remove(TKey key) |
|
|
|
=> items.Remove(WeakRef(key)); |
|
|
|
public bool Remove(TKey key) |
|
|
|
{ |
|
|
|
if (key == null) |
|
|
|
throw new ArgumentException("Null key", nameof(key)); |
|
|
|
|
|
|
|
items.Remove(WeakRef(key)); |
|
|
|
} |
|
|
|
|
|
|
|
public ConditionalWeakTable() |
|
|
|
=> GCTracker.OnGC += OnGC; |
|
|
|