PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/stable-1.0.3/Client/RemoteObject.cs

#
C# | 179 lines | 138 code | 33 blank | 8 comment | 2 complexity | 15864a4024c61120c63cd66b73366a0b MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //-----------------------------------------------------------------------
  2. // <copyright>
  3. // Copyright (C) Ruslan Yakushev for the PHP Manager for IIS project.
  4. //
  5. // This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
  6. // See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
  7. // </copyright>
  8. //-----------------------------------------------------------------------
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. namespace Web.Management.PHP
  13. {
  14. internal class RemoteObjectCollection<T> : IRemoteObject, ICollection, IList<T> where T : IRemoteObject, new()
  15. {
  16. private List<T> _list;
  17. public RemoteObjectCollection(ArrayList sourceList)
  18. {
  19. if (sourceList != null)
  20. {
  21. Initialize(sourceList);
  22. }
  23. else
  24. {
  25. _list = new List<T>();
  26. }
  27. }
  28. public RemoteObjectCollection()
  29. {
  30. _list = new List<T>();
  31. }
  32. public int Count
  33. {
  34. get
  35. {
  36. return _list.Count;
  37. }
  38. }
  39. public bool IsReadOnly
  40. {
  41. get
  42. {
  43. return ((IList)_list).IsReadOnly;
  44. }
  45. }
  46. public T this[int index]
  47. {
  48. get
  49. {
  50. return (T)_list[index];
  51. }
  52. set
  53. {
  54. _list[index] = value;
  55. }
  56. }
  57. public void Add(T item)
  58. {
  59. _list.Add(item);
  60. }
  61. public void Clear()
  62. {
  63. _list.Clear();
  64. }
  65. public bool Contains(T item)
  66. {
  67. return _list.Contains(item);
  68. }
  69. public void CopyTo(T[] array, int arrayIndex)
  70. {
  71. _list.CopyTo(array, arrayIndex);
  72. }
  73. public object GetData()
  74. {
  75. ArrayList items = new ArrayList(_list.Count);
  76. foreach (T item in _list)
  77. {
  78. items.Add(item.GetData());
  79. }
  80. return items;
  81. }
  82. public IEnumerator<T> GetEnumerator()
  83. {
  84. return _list.GetEnumerator();
  85. }
  86. public int IndexOf(T item)
  87. {
  88. return _list.IndexOf(item);
  89. }
  90. private void Initialize(ArrayList sourceList)
  91. {
  92. _list = new List<T>(sourceList.Count);
  93. foreach (object o in sourceList)
  94. {
  95. T item = new T();
  96. item.SetData(o);
  97. _list.Add(item);
  98. }
  99. }
  100. public void Insert(int index, T item)
  101. {
  102. _list.Insert(index, item);
  103. }
  104. public bool Remove(T item)
  105. {
  106. return _list.Remove(item);
  107. }
  108. public void RemoveAt(int index)
  109. {
  110. _list.RemoveAt(index);
  111. }
  112. IEnumerator IEnumerable.GetEnumerator()
  113. {
  114. return GetEnumerator();
  115. }
  116. public void SetData(object o)
  117. {
  118. Initialize((ArrayList)o);
  119. }
  120. #region ICollection Members
  121. void ICollection.CopyTo(Array array, int index)
  122. {
  123. ((ICollection)_list).CopyTo(array, index);
  124. }
  125. bool ICollection.IsSynchronized
  126. {
  127. get
  128. {
  129. return ((ICollection)_list).IsSynchronized;
  130. }
  131. }
  132. object ICollection.SyncRoot
  133. {
  134. get
  135. {
  136. return ((ICollection)_list).SyncRoot;
  137. }
  138. }
  139. #endregion
  140. }
  141. internal interface IRemoteObject
  142. {
  143. object GetData();
  144. void SetData(object o);
  145. }
  146. }