public int Count
{
- get { return _list.Count; }
+ get
+ {
+ lock (_list)
+ return _list.Count;
+ }
}
bool ICollection<T>.IsReadOnly
public IEnumerator<T> GetEnumerator()
{
- ReadOnlyCollection<T> snap = _snapshot;
- if (snap == null)
+ lock (_list)
{
- lock (_list)
+ ReadOnlyCollection<T> snap = _snapshot;
+ if (snap == null)
+ {
_snapshot = snap = new ReadOnlyCollection<T>(_list.ToList());
+ }
+ return snap?.GetEnumerator();
}
-
- return snap?.GetEnumerator();
}
public int IndexOf(T item)
{
get
{
- ReadOnlyCollection<T> snap = _snapshot;
- if (snap != null)
- return snap[index];
-
lock (_list)
+ {
+ ReadOnlyCollection<T> snap = _snapshot;
+ if (snap != null)
+ return snap[index];
+
return _list[index];
+ }
}
set