DFLayoutDoubleFieldProperties.cs 1016 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace InABox.Core
  2. {
  3. public class DFLayoutDoubleFieldProperties : DFLayoutFieldProperties<double>
  4. {
  5. public DFLayoutDoubleFieldProperties()
  6. {
  7. Format = "F2";
  8. }
  9. public string Format { get; set; }
  10. public override string FormatValue(object value)
  11. {
  12. return string.Format("{0" + (string.IsNullOrWhiteSpace(Format) ? "" : ":" + Format) + "}", value);
  13. }
  14. public override object? ParseValue(object value)
  15. {
  16. if (value is double)
  17. return value;
  18. if (double.TryParse(value as string, out var result))
  19. return result;
  20. return null;
  21. }
  22. protected override void LoadProperties()
  23. {
  24. base.LoadProperties();
  25. Format = GetProperty("Format", Format);
  26. }
  27. protected override void SaveProperties()
  28. {
  29. base.SaveProperties();
  30. SetProperty("Format", Format);
  31. }
  32. }
  33. }