SynchronizedList.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. return _list.IndexOf (item);
  16. }
  17. }
  18. public void Insert (int index, T item)
  19. {
  20. lock (_list) {
  21. _list.Insert (index, item);
  22. }
  23. }
  24. public void RemoveAt (int index)
  25. {
  26. lock (_list) {
  27. _list.RemoveAt (index);
  28. }
  29. }
  30. void ICollection<T>.Add (T item)
  31. {
  32. lock (_list) {
  33. _list.Add (item);
  34. }
  35. }
  36. void ICollection<T>.Clear ()
  37. {
  38. lock (_list) {
  39. _list.Clear ();
  40. }
  41. }
  42. bool ICollection<T>.Contains (T item)
  43. {
  44. lock (_list) {
  45. return _list.Contains (item);
  46. }
  47. }
  48. void ICollection<T>.CopyTo (T[] array, int arrayIndex)
  49. {
  50. lock (_list) {
  51. _list.CopyTo (array, arrayIndex);
  52. }
  53. }
  54. bool ICollection<T>.Remove (T item)
  55. {
  56. lock (_list) {
  57. return _list.Remove (item);
  58. }
  59. }
  60. IEnumerator<T> IEnumerable<T>.GetEnumerator ()
  61. {
  62. return _list.GetEnumerator ();
  63. }
  64. IEnumerator IEnumerable.GetEnumerator ()
  65. {
  66. return _list.GetEnumerator ();
  67. }
  68. public T this[int index] {
  69. get {
  70. lock (_list) {
  71. return _list[index];
  72. }
  73. }
  74. set {
  75. lock (_list) {
  76. _list[index] = value;
  77. }
  78. }
  79. }
  80. int ICollection<T>.Count {
  81. get {
  82. lock (_list) {
  83. return _list.Count;
  84. }
  85. }
  86. }
  87. bool ICollection<T>.IsReadOnly {
  88. get { return _list.IsReadOnly; }
  89. }
  90. }
  91. }