ShapeSpatialDataConverter.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. using System.Globalization;
  6. namespace FastReport.Map
  7. {
  8. internal class ShapeSpatialDataConverter : TypeConverter
  9. {
  10. public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context,
  11. object value, Attribute[] attributes)
  12. {
  13. return TypeDescriptor.GetProperties(value, attributes);
  14. }
  15. public override bool GetPropertiesSupported(ITypeDescriptorContext context)
  16. {
  17. return true;
  18. }
  19. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  20. {
  21. if (sourceType == typeof(string))
  22. return true;
  23. return base.CanConvertFrom(context, sourceType);
  24. }
  25. public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
  26. {
  27. if (destinationType == typeof(string))
  28. return true;
  29. return base.CanConvertTo(context, destinationType);
  30. }
  31. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  32. {
  33. if (value is string)
  34. {
  35. ShapeSpatialData data = new ShapeSpatialData();
  36. data.SetAsString((string)value);
  37. return data;
  38. }
  39. return base.ConvertFrom(context, culture, value);
  40. }
  41. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  42. {
  43. if (destinationType == typeof(string))
  44. {
  45. ShapeSpatialData data = value as ShapeSpatialData;
  46. if (data == null)
  47. return "";
  48. return data.GetAsString();
  49. }
  50. return base.ConvertTo(context, culture, value, destinationType);
  51. }
  52. }
  53. }