2 * Namespace: System.Web.UI.WebControls
\r
3 * Class: FontNamesConverter
\r
5 * Author: Gaurav Vaish
\r
6 * Maintainer: gvaish@iitk.ac.in
\r
7 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
\r
8 * Implementation: yes
\r
11 * (C) Gaurav Vaish (2002)
\r
15 using System.Globalization;
\r
16 using System.ComponentModel;
\r
18 using System.Web.UI;
\r
20 namespace System.Web.UI.WebControls
\r
22 public class FontNamesConverter : TypeConverter
\r
24 public FontNamesConverter(): base()
\r
28 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
\r
30 return (sourceType == typeof(string));
\r
33 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
\r
37 string fontNames = (string)value;
\r
38 if(fontNames.Length == 0)
\r
40 return (new string[0]);
\r
42 string[] names = fontNames.Split(new char[] { ','});
\r
43 for(int i=0; i < names.Length; i++)
\r
45 names[i] = names[i].Trim();
\r
49 throw GetConvertFromException(value);
\r
52 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
\r
54 if(destinationType == typeof(string))
\r
56 if(value == null || ((string[])value) == null)
\r
57 return String.Empty;
\r
58 return String.Join(",", (string[])value);
\r
60 throw GetConvertToException(value, destinationType);
\r