[corlib] Parse datetime string using culture calendar. Fixes #18052
[mono.git] / mcs / class / corlib / System.Collections.ObjectModel / ReadOnlyCollection.cs
1 // -*- Mode: csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 //
3 // System.Collections.ObjectModel.ReadOnlyCollection
4 //
5 // Authors:
6 //    Zoltan Varga (vargaz@gmail.com)
7 //    David Waite (mass@akuma.org)
8 //    Marek Safar (marek.safar@gmail.com)
9 //
10 // (C) 2005 Novell, Inc.
11 // (C) 2005 David Waite
12 //
13
14 //
15 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
16 // Copyright (C) 2005 David Waite
17 // Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
18 //
19 // Permission is hereby granted, free of charge, to any person obtaining
20 // a copy of this software and associated documentation files (the
21 // "Software"), to deal in the Software without restriction, including
22 // without limitation the rights to use, copy, modify, merge, publish,
23 // distribute, sublicense, and/or sell copies of the Software, and to
24 // permit persons to whom the Software is furnished to do so, subject to
25 // the following conditions:
26 // 
27 // The above copyright notice and this permission notice shall be
28 // included in all copies or substantial portions of the Software.
29 // 
30 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 //
38
39 using System;
40 using System.Collections.Generic;
41 using System.Runtime.InteropServices;
42 using System.Diagnostics;
43
44 namespace System.Collections.ObjectModel
45 {
46         [ComVisible (false)]
47         [Serializable]
48         [DebuggerDisplay ("Count={Count}")]
49         [DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
50         public class ReadOnlyCollection<T> : IList<T>, IList
51 #if NET_4_5
52                 , IReadOnlyList<T>
53 #endif
54         {
55                 IList <T> list;
56                 
57                 public ReadOnlyCollection (IList <T> list)
58                 {
59                         if (list == null)
60                                 throw new ArgumentNullException ("list");
61                         this.list = list;
62                 }
63
64                 void ICollection<T>.Add (T item)
65                 {
66                         throw new NotSupportedException ();
67                 }
68                 
69                 void ICollection<T>.Clear ()
70                 {
71                         throw new NotSupportedException ();
72                 }
73
74                 public bool Contains (T value)
75                 {
76                         return list.Contains (value);
77                 }
78
79                 public void CopyTo (T [] array, int index)
80                 {
81                         list.CopyTo (array, index);
82                 }
83
84                 public IEnumerator <T> GetEnumerator ()
85                 {
86                         return list.GetEnumerator ();
87                 }
88
89                 public int IndexOf (T value)
90                 {
91                         return list.IndexOf (value);
92                 }
93
94                 void IList<T>.Insert (int index, T item)
95                 {
96                         throw new NotSupportedException ();
97                 }
98
99                 bool ICollection<T>.Remove (T item)
100                 {
101                         throw new NotSupportedException ();
102                 }
103
104                 void IList<T>.RemoveAt (int index)
105                 {
106                         throw new NotSupportedException ();
107                 }
108
109                 public int Count {
110                         get { return list.Count; }
111                 }
112
113                 protected IList<T> Items {
114                         get { return list; }
115                 }
116
117                 public T this [int index] {
118                         get { return list [index]; }
119                 }
120
121                 T IList<T>.this [int index] {
122                         get { return this [index]; }
123                         set { throw new NotSupportedException (); }
124                 }
125
126                 bool ICollection<T>.IsReadOnly {
127                         get { return true; }
128                 }
129
130 #region Not generic interface implementations
131                 void ICollection.CopyTo (Array array, int index)
132                 {
133                         ((ICollection)list).CopyTo (array, index);
134                 }
135                                 
136                 IEnumerator IEnumerable.GetEnumerator ()
137                 {
138                         return ((IEnumerable) list).GetEnumerator ();
139                 }
140                 
141                 int IList.Add (object value)
142                 {
143                         throw new NotSupportedException ();
144                 }
145                 
146                 void IList.Clear ()
147                 {
148                         throw new NotSupportedException ();
149                 }
150
151                 bool IList.Contains (object value)
152                 {
153                         if (CollectionHelpers.IsValidItem<T> (value))
154                                 return list.Contains ((T) value);
155                         return false;
156                 }
157                 
158                 int IList.IndexOf (object value)
159                 {
160                         if (CollectionHelpers.IsValidItem<T> (value))
161                                 return list.IndexOf ((T) value);
162                         return -1;
163                 }
164                 
165                 void IList.Insert (int index, object value)
166                 {
167                         throw new NotSupportedException ();
168                 }
169                 
170                 void IList.Remove (object value)
171                 {
172                         throw new NotSupportedException ();
173                 }
174                 
175                 void IList.RemoveAt (int index)
176                 {
177                         throw new NotSupportedException ();
178                 }
179
180                 bool ICollection.IsSynchronized {
181                         get { return false; }
182                 }
183                 
184                 object ICollection.SyncRoot {
185                         get { return this; }
186                 }
187
188                 bool IList.IsFixedSize {
189                         get { return true; }
190                 }
191                 
192                 bool IList.IsReadOnly {
193                         get { return true; }
194                 }
195                 
196                 object IList.this [int index] {
197                         get { return list [index]; }
198                         set { throw new NotSupportedException (); }
199                 }
200 #endregion
201         }
202 }