2
0

FontNamesConverter.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.ComponentModel;
  15. using System.Web;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. public class FontNamesConverter : TypeConverter
  20. {
  21. public FontNamesConverter(): base()
  22. {
  23. }
  24. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  25. {
  26. return (sourceType == typeof(string));
  27. }
  28. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  29. {
  30. if(value is string)
  31. {
  32. string fontNames = (string)value;
  33. if(fontNames.Length == 0)
  34. {
  35. return (new string[0]);
  36. }
  37. string[] names = fontNames.Split(new char[] { ','});
  38. foreach(string current in names)
  39. {
  40. current = current.Trim();
  41. }
  42. return names;
  43. }
  44. throw GetConvertFromException(value);
  45. }
  46. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  47. {
  48. if(destinationType is typeof(string))
  49. {
  50. if(value == null || ((string[])value) == null)
  51. return String.Empty;
  52. return String.Join(",", (string[])value);
  53. }
  54. throw GetConvertToException(value, destinationType);
  55. }
  56. }
  57. }