DFLayoutPINFieldProperties.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. namespace InABox.Core
  2. {
  3. public class DFLayoutPINFieldProperties : DFLayoutFieldProperties<string, string?>
  4. {
  5. public int Length { get; set; }
  6. public DFLayoutPINFieldProperties()
  7. {
  8. Length = 4;
  9. }
  10. public override string FormatValue(string? value)
  11. {
  12. return value ?? "";
  13. }
  14. public override string? DeserializeValue(DFLoadStorageEntry entry)
  15. {
  16. var value = entry.GetValue();
  17. if(value is int i)
  18. {
  19. return i.ToString();
  20. }
  21. return value?.ToString();
  22. }
  23. public override string GetValue(string? value)
  24. {
  25. return value ?? Default;
  26. }
  27. public override void SerializeValue(DFSaveStorageEntry entry, string? value)
  28. {
  29. entry.SetValue(value);
  30. }
  31. protected override void LoadProperties()
  32. {
  33. base.LoadProperties();
  34. Length = GetProperty("Length", 4);
  35. }
  36. protected override void SaveProperties()
  37. {
  38. base.SaveProperties();
  39. SetProperty("Length", Length);
  40. }
  41. }
  42. }