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