DataCycleConverter.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace IndexFormula.Finance
  2. {
  3. using System;
  4. using System.ComponentModel;
  5. using System.Globalization;
  6. public class DataCycleConverter : ExpandableObjectConverter
  7. {
  8. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  9. {
  10. return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
  11. }
  12. public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
  13. {
  14. return ((destinationType == typeof(string)) || base.CanConvertTo(context, destinationType));
  15. }
  16. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  17. {
  18. if (value is string)
  19. {
  20. return DataCycle.Parse((string) value);
  21. }
  22. return base.ConvertFrom(context, culture, value);
  23. }
  24. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  25. {
  26. if (destinationType == typeof(string))
  27. {
  28. return value.ToString();
  29. }
  30. return base.ConvertTo(context, culture, value, destinationType);
  31. }
  32. }
  33. }