FontNamesConverter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: FontNamesConverter
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.Globalization;
  15. using System.ComponentModel;
  16. using System.Web;
  17. using System.Web.UI;
  18. namespace System.Web.UI.WebControls
  19. {
  20. public class FontNamesConverter : TypeConverter
  21. {
  22. public FontNamesConverter(): base()
  23. {
  24. }
  25. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  26. {
  27. return (sourceType == typeof(string));
  28. }
  29. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  30. {
  31. if(value is string)
  32. {
  33. string fontNames = (string)value;
  34. if(fontNames.Length == 0)
  35. {
  36. return (new string[0]);
  37. }
  38. string[] names = fontNames.Split(new char[] { ','});
  39. for(int i=0; i < names.Length; i++)
  40. {
  41. names[i] = names[i].Trim();
  42. }
  43. return names;
  44. }
  45. throw GetConvertFromException(value);
  46. }
  47. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  48. {
  49. if(destinationType == typeof(string))
  50. {
  51. if(value == null || ((string[])value) == null)
  52. return String.Empty;
  53. return String.Join(",", (string[])value);
  54. }
  55. throw GetConvertToException(value, destinationType);
  56. }
  57. }
  58. }