DFLayoutIntegerFieldProperties.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Newtonsoft.Json.Schema;
  2. using System;
  3. namespace InABox.Core
  4. {
  5. public class DFLayoutIntegerFieldProperties : DFLayoutFieldProperties<int>
  6. {
  7. public DFLayoutIntegerFieldProperties()
  8. {
  9. Format = "";
  10. }
  11. public string Format { get; set; }
  12. public override string FormatValue(object? value)
  13. {
  14. return string.Format("{0" + (string.IsNullOrWhiteSpace(Format) ? "" : ":" + Format) + "}", value);
  15. }
  16. public override object? ParseValue(object? value)
  17. {
  18. if (value is null)
  19. return null;
  20. if (value.GetType().IsNumeric())
  21. {
  22. return Convert.ToInt32(value);
  23. }
  24. if (int.TryParse(value as string, out var result))
  25. return result;
  26. return null;
  27. }
  28. protected override void LoadProperties()
  29. {
  30. base.LoadProperties();
  31. Format = GetProperty("Format", Format);
  32. }
  33. protected override void SaveProperties()
  34. {
  35. base.SaveProperties();
  36. SetProperty("Format", Format);
  37. }
  38. }
  39. }