2 // TypeConverter for SL 2
4 // Copyright (C) 2008 Novell, Inc.
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Globalization;
31 namespace System.ComponentModel {
33 public class TypeConverter {
35 public bool CanConvertFrom (Type sourceType)
37 return CanConvertFrom (null, sourceType);
40 public virtual bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
45 public object ConvertFrom (object value)
47 return ConvertFrom (null, CultureInfo.CurrentCulture, value);
50 public virtual object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
52 throw new NotImplementedException ();
55 public object ConvertFromString (string text)
57 return ConvertFrom (null, null, text);
60 public bool CanConvertTo (Type destinationType)
62 return CanConvertTo (null, destinationType);
65 public virtual bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
70 public object ConvertTo (object value, Type destinationType)
72 return ConvertTo (null, CultureInfo.CurrentCulture, value, destinationType);
75 public virtual object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
77 throw new NotImplementedException ();
80 public string ConvertToString (object value)
82 return (string) ConvertTo (null, CultureInfo.CurrentCulture, value, typeof(string));