PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 179 lines | 138 code | 33 blank | 8 comment | 2 complexity | 44dd1f3156bdae17b3b1bbfeb453fb29 MD5 | raw file
  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
 10using System;
 11using System.Collections;
 12using System.Collections.Generic;
 13
 14namespace Web.Management.PHP
 15{
 16
 17    public sealed class RemoteObjectCollection<T> : IRemoteObject, ICollection, IList<T> where T : IRemoteObject, new()
 18    {
 19
 20        private List<T> _list;
 21
 22        public RemoteObjectCollection(ArrayList sourceList)
 23        {
 24            if (sourceList != null)
 25            {
 26                Initialize(sourceList);
 27            }
 28            else
 29            {
 30                _list = new List<T>();
 31            }
 32        }
 33
 34        public RemoteObjectCollection()
 35        {
 36            _list = new List<T>();
 37        }
 38
 39        public int Count
 40        {
 41            get
 42            {
 43                return _list.Count;
 44            }
 45        }
 46
 47        public bool IsReadOnly
 48        {
 49            get
 50            {
 51                return ((IList)_list).IsReadOnly;
 52            }
 53        }
 54
 55        public T this[int index]
 56        {
 57            get
 58            {
 59                return (T)_list[index];
 60            }
 61            set
 62            {
 63                _list[index] = value;
 64            }
 65        }
 66
 67        public void Add(T item)
 68        {
 69            _list.Add(item);
 70        }
 71
 72        public void Clear()
 73        {
 74            _list.Clear();
 75        }
 76
 77        public bool Contains(T item)
 78        {
 79            return _list.Contains(item);
 80        }
 81
 82        public void CopyTo(T[] array, int arrayIndex)
 83        {
 84            _list.CopyTo(array, arrayIndex);
 85        }
 86
 87        public object GetData()
 88        {
 89            ArrayList items = new ArrayList(_list.Count);
 90            foreach (T item in _list)
 91            {
 92                items.Add(item.GetData());
 93            }
 94
 95            return items;
 96        }
 97
 98        public IEnumerator<T> GetEnumerator()
 99        {
100            return _list.GetEnumerator();
101        }
102
103        public int IndexOf(T item)
104        {
105            return _list.IndexOf(item);
106        }
107
108        private void Initialize(ArrayList sourceList)
109        {
110            _list = new List<T>(sourceList.Count);
111
112            foreach (object o in sourceList)
113            {
114                T item = new T();
115                item.SetData(o);
116                _list.Add(item);
117            }
118        }
119
120        public void Insert(int index, T item)
121        {
122            _list.Insert(index, item);
123        }
124
125        public bool Remove(T item)
126        {
127            return _list.Remove(item);
128        }
129
130        public void RemoveAt(int index)
131        {
132            _list.RemoveAt(index);
133        }
134
135        IEnumerator IEnumerable.GetEnumerator()
136        {
137            return GetEnumerator();
138        }
139
140        public void SetData(object o)
141        {
142            Initialize((ArrayList)o);
143        }
144
145        #region ICollection Members
146
147        void ICollection.CopyTo(Array array, int index)
148        {
149            ((ICollection)_list).CopyTo(array, index);
150        }
151
152        bool ICollection.IsSynchronized
153        {
154            get
155            {
156                return ((ICollection)_list).IsSynchronized;
157            }
158        }
159
160        object ICollection.SyncRoot
161        {
162            get
163            {
164                return ((ICollection)_list).SyncRoot;
165            }
166        }
167
168        #endregion
169    }
170
171    public interface IRemoteObject
172    {
173
174        object GetData();
175
176        void SetData(object o);
177
178    }
179}