2002-07-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System / System.ComponentModel / TypeConverter.cs
1 //
2 // System.ComponentModel.TypeConverter
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 //
9
10 using System;
11 using System.Collections;
12 using System.Globalization;
13
14 namespace System.ComponentModel {
15
16 public class TypeConverter
17 {
18         public TypeConverter ()
19         {
20         }
21
22         public bool CanConvertFrom (Type sourceType)
23         {
24                 return CanConvertFrom (null, sourceType);
25         }
26         
27         [MonoTODO]
28         public virtual bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
29         {
30                 throw new NotImplementedException ();
31         }
32
33         public bool CanConvertTo (Type destinationType)
34         {
35                 return CanConvertTo (null, destinationType);
36         }
37         
38         [MonoTODO]
39         public virtual bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
40         {
41                 throw new NotImplementedException ();
42         }
43
44         public object ConvertFrom (object o)
45         {
46                 return ConvertFrom (null, CultureInfo.CurrentCulture, o);
47         }
48
49         [MonoTODO]
50         public virtual object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
51         {
52                 throw new NotImplementedException ();
53         }
54         
55         public virtual object ConvertFromInvariantString (string text)
56         {
57                 return ConvertFromInvariantString (null, text); 
58         }
59
60         [MonoTODO]
61         public virtual object ConvertFromInvariantString (ITypeDescriptorContext context, string text)
62         {
63                 throw new NotImplementedException ();
64         }
65
66         public object ConvertFromString (string s)
67         {
68                 return ConvertFrom (s);
69         }
70
71         public object ConvertFromString (ITypeDescriptorContext context, string text)
72         {
73                 return ConvertFromString (context, CultureInfo.CurrentCulture, text);
74         }
75
76         [MonoTODO]
77         public object ConvertFromString (ITypeDescriptorContext context, CultureInfo culture, string text)
78         {
79                 throw new NotImplementedException ();
80         }
81
82         [MonoTODO]
83         public object ConvertTo (object value, Type destinationType)
84         {
85                 throw new NotImplementedException ();
86         }
87         [MonoTODO]
88         public virtual object ConvertTo (ITypeDescriptorContext context,
89                                          CultureInfo culture,
90                                          object value,
91                                          Type destinationType)
92         {
93                 throw new NotImplementedException ();
94         }
95
96         [MonoTODO]
97         public string ConvertToInvariantString (object value)
98         {
99                 throw new NotImplementedException ();
100         }
101
102         [MonoTODO]
103         public string ConvertToInvariantString (ITypeDescriptorContext context, object value)
104         {
105                 throw new NotImplementedException ();
106         }
107
108         [MonoTODO]
109         public string ConvertToString (object value)
110         {
111                 throw new NotImplementedException ();
112         }
113
114         [MonoTODO]
115         public string ConvertToString (ITypeDescriptorContext context, object value)
116         {
117                 throw new NotImplementedException ();
118         }
119
120         [MonoTODO]
121         public string ConvertToString (ITypeDescriptorContext context, CultureInfo culture, object value)
122         {
123                 throw new NotImplementedException ();
124         }
125
126         [MonoTODO]
127         public object CreateInstance (IDictionary propertyValues)
128         {
129                 throw new NotImplementedException ();
130         }
131
132         [MonoTODO]
133         public virtual object CreateInstance (ITypeDescriptorContext context, IDictionary propertyValues)
134         {
135                 throw new NotImplementedException ();
136         }
137
138         [MonoTODO]
139         public bool GetCreateInstanceSupported ()
140         {
141                 throw new NotImplementedException ();
142         }
143
144         [MonoTODO]
145         public virtual bool GetCreateInstanceSupported (ITypeDescriptorContext context)
146         {
147                 throw new NotImplementedException ();
148         }
149
150         [MonoTODO]
151         public PropertyDescriptorCollection GetProperties (object value)
152         {
153                 throw new NotImplementedException ();
154         }
155
156         [MonoTODO]
157         public PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value)
158         {
159                 throw new NotImplementedException ();
160         }
161
162         [MonoTODO]
163         public virtual PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context,
164                                                                    object value,
165                                                                    Attribute[] attributes)
166         {
167                 throw new NotImplementedException ();
168         }
169
170         [MonoTODO]
171         public bool GetPropertiesSupported ()
172         {
173                 throw new NotImplementedException ();
174         }
175
176         [MonoTODO]
177         public virtual bool GetPropertiesSupported (ITypeDescriptorContext context)
178         {
179                 throw new NotImplementedException ();
180         }
181
182         [MonoTODO]
183         public ICollection GetStandardValues ()
184         {
185                 throw new NotImplementedException ();
186         }
187
188         [MonoTODO]
189         public virtual StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
190         {
191                 throw new NotImplementedException ();
192         }
193
194         [MonoTODO]
195         public bool GetStandardValuesExclusive ()
196         {
197                 throw new NotImplementedException ();
198         }
199
200         [MonoTODO]
201         public virtual bool GetStandardValuesExclusive (ITypeDescriptorContext context)
202         {
203                 throw new NotImplementedException ();
204         }
205
206         [MonoTODO]
207         public bool GetStandardValuesSupported ()
208         {
209                 throw new NotImplementedException ();
210         }
211
212         [MonoTODO]
213         public virtual bool GetStandardValuesSupported (ITypeDescriptorContext context)
214         {
215                 throw new NotImplementedException ();
216         }
217
218         [MonoTODO]
219         public bool IsValid (object value)
220         {
221                 throw new NotImplementedException ();
222         }
223
224         [MonoTODO]
225         public virtual bool IsValid (ITypeDescriptorContext context, object value)
226         {
227                 throw new NotImplementedException ();
228         }
229
230         public class StandardValuesCollection : ICollection, IEnumerable
231         {
232                 private ICollection values;
233                 
234                 public StandardValuesCollection (ICollection values)
235                 {
236                         this.values = values;
237                 }
238
239                 public void CopyTo (Array array, int index)
240                 {
241                         values.CopyTo (array, index);
242                 }
243
244                 public IEnumerator GetEnumerator ()
245                 {
246                         return values.GetEnumerator ();
247                 }
248
249                 bool ICollection.IsSynchronized
250                 {
251                         get { return false; }
252                 }
253
254                 object ICollection.SyncRoot
255                 {
256                         get { return null; }
257                 }
258
259                 int ICollection.Count
260                 {
261                         get { return this.Count; }
262                 }
263
264                 public int Count
265                 {
266                         get { return values.Count; }
267                 }
268
269                 public object this [int index]
270                 {
271                         get { return ((IList) values) [index]; }
272                 }
273         }
274
275         protected abstract class SimplePropertyDescriptor : PropertyDescriptor
276         {
277                 private Type componentType;
278                 private Type propertyType;
279                 
280                 public SimplePropertyDescriptor (Type componentType,
281                                                  string name,
282                                                  Type propertyType) :
283                         this (componentType, name, propertyType, new Attribute [0])
284                 {
285                 }
286
287                 public SimplePropertyDescriptor (Type componentType,
288                                                  string name,
289                                                  Type propertyType,
290                                                  Attribute [] attributes) : base (name, attributes)
291                 {
292                         this.componentType = componentType;
293                         this.propertyType = propertyType;
294                 }
295
296                 public override Type ComponentType
297                 {
298                         get { return componentType; }
299                 }
300
301                 public override Type PropertyType
302                 {
303                         get { return propertyType; }
304                 }
305
306                 public override bool IsReadOnly
307                 {
308                         get {
309                                 return Attributes.Contains (ReadOnlyAttribute.Yes);
310                         }
311                 }
312         }
313 }
314 }
315