ArrowCapConverter.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace IndexFormula.Finance
  2. {
  3. using System;
  4. using System.ComponentModel;
  5. using System.Globalization;
  6. public class ArrowCapConverter : ExpandableObjectConverter
  7. {
  8. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  9. {
  10. return (((sourceType == null) || (sourceType == typeof(string))) || base.CanConvertFrom(context, sourceType));
  11. }
  12. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  13. {
  14. if (value == null)
  15. {
  16. return null;
  17. }
  18. if (value is string)
  19. {
  20. string[] strArray = (value as string).Split(new char[] { ',' });
  21. if (strArray.Length == 3)
  22. {
  23. return new ArrowCap(int.Parse(strArray[0]), int.Parse(strArray[1]), bool.Parse(strArray[2]));
  24. }
  25. return null;
  26. }
  27. return base.ConvertFrom(context, culture, value);
  28. }
  29. public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  30. {
  31. return new TypeConverter.StandardValuesCollection(new string[] { "10,10,false", "10,10,true", "" });
  32. }
  33. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
  34. {
  35. return false;
  36. }
  37. public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  38. {
  39. return true;
  40. }
  41. }
  42. }