2
0

FontUnitConverter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: FontUnitConverter
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 60%
  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 FontUnitConverter : TypeConverter
  20. {
  21. public FontUnitConverter(): base()
  22. {
  23. }
  24. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  25. {
  26. if(sourceType == typeof(string))
  27. return true;
  28. return base.CanConvertFrom(context, sourceType);
  29. }
  30. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  31. {
  32. if(value == null)
  33. return null;
  34. if(value is string)
  35. {
  36. string val = ((string)value).Trim();
  37. if(val.Length == 0)
  38. {
  39. return FontUnit.Empty;
  40. }
  41. return FontUnit.Parse(val, culture);
  42. }
  43. return base.ConvertFrom(context, culture, value);
  44. }
  45. [MonoTODO("ConvertTo")]
  46. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  47. {
  48. if(value == null || !(value is FontUnit))
  49. return String.Empty;
  50. FontUnit val = (FontUnit)value;
  51. if(val == FontUnit.NotSet)
  52. {
  53. return String.Empty;
  54. }
  55. throw new NotImplementedException();
  56. }
  57. }
  58. }