FontUnitConverter.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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: 95%
  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 FontUnitConverter : TypeConverter
  21. {
  22. public FontUnitConverter(): base()
  23. {
  24. }
  25. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  26. {
  27. if(sourceType == typeof(string))
  28. return true;
  29. return base.CanConvertFrom(context, sourceType);
  30. }
  31. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  32. {
  33. if(value == null)
  34. return null;
  35. if(value is string)
  36. {
  37. string val = ((string)value).Trim();
  38. if(val.Length == 0)
  39. {
  40. return FontUnit.Empty;
  41. }
  42. return FontUnit.Parse(val, culture);
  43. }
  44. return base.ConvertFrom(context, culture, value);
  45. }
  46. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  47. {
  48. if(value != null && value is FontUnit)
  49. {
  50. FontUnit val = (FontUnit)value;
  51. if(val.Type == FontSize.NotSet)
  52. {
  53. return String.Empty;
  54. }
  55. return val.ToString(culture);
  56. }
  57. return base.ConvertTo(context, culture, value, destinationType);
  58. }
  59. [MonoTODO("GetStandardValues")]
  60. public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  61. {
  62. throw new NotImplementedException();
  63. }
  64. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
  65. {
  66. return false;
  67. }
  68. public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  69. {
  70. return true;
  71. }
  72. }
  73. }