SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
SerialisableList.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Text;
5 using System.Xml.Serialization;
6 using System.Runtime.InteropServices;
7 
8 namespace Seci
9 {
16  [ComVisible(false)]
17  public class SerialisableList<T> : IEnumerable<T>, ICloneable
18  {
19  private List<T> _list = new List<T>();
20 
21  //Properties
22  public T this[int index] { get { return _list[index]; } set { _list[index] = value; } }
23  public int Count { get { return _list.Count; } }
24 
25  #region Add Items
26 
31  public void Add(T item)
32  {
33  _list.Add(item);
34  }
35 
40  public void AddRange(IEnumerable<T> collection)
41  {
42  _list.AddRange(collection);
43  }
44 
50  public void Insert(int index, T item)
51  {
52  _list.Insert(index, item);
53  }
54 
55  #endregion
56 
57  #region Remove Items
58 
63  public void RemoveAt(int index)
64  {
65  _list.RemoveAt(index);
66  }
67 
73  public Boolean Remove(T item)
74  {
75  return _list.Remove(item);
76  }
77 
83  public void RemoveRange(int index, int count)
84  {
85  _list.RemoveRange(index, count);
86  }
87 
93  public int RemoveAll(Predicate<T> match)
94  {
95  return _list.RemoveAll(match);
96  }
97 
101  public void Clear()
102  {
103  _list.Clear();
104  }
105 
106  #endregion
107 
108  #region Other standard stuff
109 
116  public List<T> GetRange(int index, int count)
117  {
118  return _list.GetRange(index, count);
119  }
120 
126  public Boolean Contains(T item)
127  {
128  return _list.Contains(item);
129  }
130 
135  public T[] ToArray()
136  {
137  return _list.ToArray();
138  }
139 
140  #endregion
141 
142  #region IEnumerable<T> Members
143 
149  public IEnumerator<T> GetEnumerator()
150  {
151  for (int i = 0; i < _list.Count; ++i)
152  {
153  yield return _list[i];
154  }
155  }
156 
163  System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
164  {
165  return GetEnumerator();
166  }
167 
168  #endregion
169 
170  #region ICloneable Members
171 
177  public object Clone()
178  {
179  SerialisableList<T> deepcopy = new SerialisableList<T>();
180  T itemClone;
181 
182  for (int i = 0; i < _list.Count; ++i)
183  {
184  itemClone = _list[i];
185  deepcopy.Add(itemClone);
186  }
187 
188  return deepcopy;
189  }
190 
191  #endregion
192 
193  #region Serialisation Code
194 
198  [XmlElement]
199  public T[] Items
200  {
201  get
202  {
203  return _list.ToArray();
204  }
205  set
206  {
207  if (value != null)
208  {
209  _list = new List<T>(value);
210 
211  }
212  }
213  }
214 
215  #endregion
216  }
217 }
218 
219 
void Clear()
Wrapper for standard List &quot;Clear&quot; - removes all items.
void RemoveAt(int index)
Wrapper for standard List &quot;RemoveAt&quot;.
void AddRange(IEnumerable< T > collection)
Wrapper for standard List &quot;Add&quot;.
void Add(T item)
Wrapper for standard List &quot;Add&quot;.
object Clone()
Clone - default method of ICloneable. Produces a deep-copy of the List.
void Insert(int index, T item)
Wrapper for standard List &quot;Insert&quot;.
Boolean Remove(T item)
Wrapper for standard List &quot;Remove&quot;.
int RemoveAll(Predicate< T > match)
Wrapper for standard List &quot;RemoveAll&quot;. Removes all items that match the specified predicate...
Boolean Contains(T item)
Wrapper for standard List &quot;Contains&quot;.
List< T > GetRange(int index, int count)
Wrapper for standard List &quot;GetRange&quot; - returns all items in a specified range.
void RemoveRange(int index, int count)
Wrapper for standard List &quot;RemoveRange&quot;.
Specialised generic version of the standard List class which can be converted to XML. Containss a standard List object and has wrapper methods for most of the standard List functionality plus some extras.
IEnumerator< T > GetEnumerator()
GetEnumerator - default method of IEnumerable. Provides an iterator over a generic List...
T[] ToArray()
Wrapper for standard List &quot;ToArray&quot;.