2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Data.ObjectSpaces / System.Data.ObjectSpaces / ObjectList.cs
1 //\r
2 // System.Data.ObjectSpaces.ObjectList.cs\r
3 //\r
4 // Author:\r
5 //   Mark Easton (mark.easton@blinksoftware.co.uk)\r
6 //   Tim Coleman (tim@timcoleman.com)\r
7 //\r
8 // (C) BLiNK Software Ltd.  http://www.blinksoftware.co.uk\r
9 // Copyright (C) Tim Coleman, 2003-2004\r
10 //\r
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32 \r
33 #if NET_2_0\r
34 \r
35 using System.Collections;\r
36 using System.Reflection;\r
37 \r
38 namespace System.Data.ObjectSpaces\r
39 {\r
40         [MonoTODO]\r
41         public class ObjectList : ICollection, IEnumerable, IList\r
42         {\r
43                 #region Fields\r
44 \r
45                 IList list;\r
46 \r
47                 #endregion // Fields\r
48 \r
49                 #region Constructors\r
50 \r
51                 public ObjectList () \r
52                         : this (typeof (ArrayList), null) \r
53                 {\r
54                 }\r
55 \r
56                 public ObjectList (Type type, object[] parameters)\r
57                 {\r
58                         if (type == null)\r
59                                 throw new ObjectException ();\r
60 \r
61                         bool isIList = false;\r
62                         foreach (Type t in type.GetInterfaces ())\r
63                                 if (t.Equals (typeof (IList))) {\r
64                                         isIList = true;\r
65                                         break;\r
66                                 }\r
67 \r
68                         if (!isIList)\r
69                                 throw new ObjectException ();\r
70 \r
71                         Type[] types = Type.EmptyTypes;\r
72                         if (parameters != null)\r
73                                 types = Type.GetTypeArray (parameters);\r
74 \r
75                         ConstructorInfo ci = type.GetConstructor (types);\r
76                         list = (IList) ci.Invoke (parameters);\r
77                 }\r
78 \r
79                 #endregion // Constructors\r
80 \r
81                 #region Properties\r
82 \r
83                 public int Count {\r
84                         get { return InnerList.Count; }\r
85                 }     \r
86 \r
87                 bool ICollection.IsSynchronized {       \r
88                         get { return InnerList.IsSynchronized; }\r
89                 }\r
90 \r
91                 object ICollection.SyncRoot {\r
92                         get { return InnerList.SyncRoot; }\r
93                 }\r
94                 \r
95                 public IList InnerList {\r
96                         get { return list; }\r
97                 }        \r
98                 \r
99                 public bool IsFixedSize {\r
100                         get { return InnerList.IsFixedSize; }\r
101                 }  \r
102 \r
103                 public bool IsReadOnly {\r
104                         get { return InnerList.IsReadOnly; }\r
105                 }\r
106                 \r
107                 public object this [int index] {\r
108                         get { return InnerList [index]; }\r
109                         set { InnerList [index] = value; }\r
110                 }\r
111 \r
112                 #endregion // Properties\r
113 \r
114                 #region Methods\r
115                 \r
116                 public int Add (object value)\r
117                 {\r
118                         return InnerList.Add (value);\r
119                 }\r
120                 \r
121                 public void Clear () \r
122                 {\r
123                         InnerList.Clear ();\r
124                 }\r
125                 \r
126                 public bool Contains (object value)\r
127                 {\r
128                         return InnerList.Contains (value);\r
129                 }\r
130                 \r
131                 public void CopyTo (Array array, int index) \r
132                 {\r
133                         InnerList.CopyTo (array, index);\r
134                 }\r
135                 \r
136                 public IEnumerator GetEnumerator ()\r
137                 {\r
138                         return InnerList.GetEnumerator (); \r
139                 }\r
140                 \r
141                 public int IndexOf (object value)\r
142                 {\r
143                         return InnerList.IndexOf (value);\r
144                 }\r
145                 \r
146                 public void Insert (int index, object value) \r
147                 {\r
148                         InnerList.Insert (index, value);\r
149                 }\r
150                 \r
151                 public void Remove (object value) \r
152                 {\r
153                         InnerList.Remove (value);\r
154                 }\r
155                 \r
156                 public void RemoveAt (int index) \r
157                 {\r
158                         InnerList.RemoveAt (index);\r
159                 }\r
160 \r
161                 #endregion // Methods\r
162         }\r
163 }\r
164 \r
165 #endif\r