This commit is contained in:
Łukasz Domeradzki
2024-08-18 03:14:11 +02:00
parent 5605e9a666
commit 5867a351a8
2 changed files with 9 additions and 1 deletions

View File

@@ -49,12 +49,15 @@ public sealed class ConcurrentList<T> : IList<T>, IReadOnlyList<T> where T : not
public T this[int index] {
get {
ArgumentOutOfRangeException.ThrowIfNegative(index);
using (Lock.ReaderLock()) {
return BackingCollection[index];
}
}
set {
ArgumentOutOfRangeException.ThrowIfNegative(index);
ArgumentNullException.ThrowIfNull(value);
using (Lock.WriterLock()) {

View File

@@ -51,9 +51,14 @@ public sealed class ObservableConcurrentDictionary<TKey, TValue> : IDictionary<T
IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values;
public TValue this[TKey key] {
get => BackingDictionary[key];
get {
ArgumentNullException.ThrowIfNull(key);
return BackingDictionary[key];
}
set {
ArgumentNullException.ThrowIfNull(key);
ArgumentNullException.ThrowIfNull(value);
if (BackingDictionary.TryGetValue(key, out TValue? savedValue) && EqualityComparer<TValue>.Default.Equals(savedValue, value)) {