/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System.Collections;
using System.Collections.Generic;
namespace dnSpy.Contracts.Documents {
///
///
///
///
public sealed class TList : IEnumerable {
readonly object lockObj;
readonly List list;
///
///
///
public object SyncRoot => lockObj;
///
///
///
///
///
public T this[int index] {
get {
lock (lockObj)
return list[index];
}
set {
lock (lockObj)
list[index] = value;
}
}
///
///
///
public int Count {
get {
lock (lockObj)
return list.Count;
}
}
///
///
///
///
public T[] GetElements() {
lock (lockObj)
return list.ToArray();
}
///
///
///
public TList() {
lockObj = new object();
list = new List();
}
///
///
///
///
public TList(int capacity) {
lockObj = new object();
list = new List(capacity);
}
///
///
///
///
public void AddRange(IEnumerable collection) {
lock (lockObj)
list.AddRange(collection);
}
///
///
///
///
public void Add(T item) {
lock (lockObj)
list.Add(item);
}
///
///
///
///
///
public void Insert(int index, T item) {
lock (lockObj)
list.Insert(index, item);
}
///
///
///
///
///
public bool Remove(T item) {
lock (lockObj)
return list.Remove(item);
}
///
///
///
///
public void RemoveAt(int index) {
lock (lockObj)
list.RemoveAt(index);
}
///
///
///
///
///
public int IndexOf(T item) {
lock (lockObj)
return list.IndexOf(item);
}
///
///
///
public void Clear() {
lock (lockObj)
list.Clear();
}
///
///
///
///
public IEnumerator GetEnumerator() => ((IEnumerable)GetElements()).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetElements().GetEnumerator();
}
}