SynchronizedList.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. namespace SharpCifs.Util.Sharpen
  4. {
  5. internal class SynchronizedList<T> : IList<T>
  6. {
  7. private IList<T> _list;
  8. public SynchronizedList(IList<T> list)
  9. {
  10. this._list = list;
  11. }
  12. public int IndexOf(T item)
  13. {
  14. lock (_list)
  15. {
  16. return _list.IndexOf(item);
  17. }
  18. }
  19. public void Insert(int index, T item)
  20. {
  21. lock (_list)
  22. {
  23. _list.Insert(index, item);
  24. }
  25. }
  26. public void RemoveAt(int index)
  27. {
  28. lock (_list)
  29. {
  30. _list.RemoveAt(index);
  31. }
  32. }
  33. void ICollection<T>.Add(T item)
  34. {
  35. lock (_list)
  36. {
  37. _list.Add(item);
  38. }
  39. }
  40. void ICollection<T>.Clear()
  41. {
  42. lock (_list)
  43. {
  44. _list.Clear();
  45. }
  46. }
  47. bool ICollection<T>.Contains(T item)
  48. {
  49. lock (_list)
  50. {
  51. return _list.Contains(item);
  52. }
  53. }
  54. void ICollection<T>.CopyTo(T[] array, int arrayIndex)
  55. {
  56. lock (_list)
  57. {
  58. _list.CopyTo(array, arrayIndex);
  59. }
  60. }
  61. bool ICollection<T>.Remove(T item)
  62. {
  63. lock (_list)
  64. {
  65. return _list.Remove(item);
  66. }
  67. }
  68. IEnumerator<T> IEnumerable<T>.GetEnumerator()
  69. {
  70. return _list.GetEnumerator();
  71. }
  72. IEnumerator IEnumerable.GetEnumerator()
  73. {
  74. return _list.GetEnumerator();
  75. }
  76. public T this[int index]
  77. {
  78. get
  79. {
  80. lock (_list)
  81. {
  82. return _list[index];
  83. }
  84. }
  85. set
  86. {
  87. lock (_list)
  88. {
  89. _list[index] = value;
  90. }
  91. }
  92. }
  93. int ICollection<T>.Count
  94. {
  95. get
  96. {
  97. lock (_list)
  98. {
  99. return _list.Count;
  100. }
  101. }
  102. }
  103. bool ICollection<T>.IsReadOnly
  104. {
  105. get { return _list.IsReadOnly; }
  106. }
  107. }
  108. }