| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System.Collections;
- using System.Collections.Generic;
- namespace Quadarax.Foundation.Core.Collections
- {
- public class LockedList<TElement> : IList<TElement>
- {
- #region *** Private Fields ***
- private readonly List<TElement> _list;
- #endregion
- #region *** Public Properties ***
- public int Count
- {
- get
- {
- lock (_list)
- {
- return _list.Count;
- }
- }
- }
- public bool IsReadOnly
- {
- get
- {
- lock (_list)
- {
- return ((IList<TElement>)_list).IsReadOnly;
- }
- }
- }
- #endregion
- #region *** Indexers ***
- public TElement this[int index]
- {
- get
- {
- lock (_list)
- {
- return _list[index];
- }
- }
- set
- {
- lock (_list)
- {
- _list[index] = value;
- }
- }
- }
- #endregion
- #region *** Constructors ***
- public LockedList()
- {
- _list = new List<TElement>();
- }
- public LockedList(IEnumerable<TElement> initialItems)
- {
- _list = new List<TElement>(initialItems);
- }
- public LockedList(int capacity)
- {
- _list = new List<TElement>(capacity);
- }
- #endregion
- #region *** Public Methods ***
- public IEnumerator<TElement> GetEnumerator()
- {
- lock (_list)
- {
- return _list.GetEnumerator();
- }
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- public void Add(TElement item)
- {
- lock (_list)
- {
- _list.Add(item);
- }
- }
- public void Clear()
- {
- lock (_list)
- {
- _list.Clear();
- }
- }
- public bool Contains(TElement item)
- {
- lock (_list)
- {
- return _list.Contains(item);
- }
- }
- public void CopyTo(TElement[] array, int arrayIndex)
- {
- lock (_list)
- {
- _list.CopyTo(array, arrayIndex);
- }
- }
- public bool Remove(TElement item)
- {
- lock (_list)
- {
- return _list.Remove(item);
- }
- }
- public int IndexOf(TElement item)
- {
- lock (_list)
- {
- return _list.IndexOf(item);
- }
- }
- public void Insert(int index, TElement item)
- {
- lock (_list)
- {
- _list.Insert(index, item);
- }
- }
- public void RemoveAt(int index)
- {
- lock (_list)
- {
- _list.RemoveAt(index);
- }
- }
- #endregion
- }
- }
|