DFLayoutEmbeddedImageProperties.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. namespace InABox.Core
  3. {
  4. public class DFLayoutEmbeddedImageProperties : DFLayoutFieldProperties<byte[]>
  5. {
  6. [CheckBoxEditor]
  7. public bool DisableLibrary { get; set; }
  8. public override string FormatValue(object? value)
  9. {
  10. return value != null ? "Yes" : "";
  11. }
  12. public override object? ParseValue(object? value)
  13. {
  14. if (value is byte[])
  15. return value;
  16. if (value is string str)
  17. {
  18. if (Guid.TryParse(str, out var id))
  19. {
  20. return Array.Empty<byte>();
  21. }
  22. try
  23. {
  24. return Convert.FromBase64String(str);
  25. }
  26. catch (Exception e)
  27. {
  28. return null;
  29. }
  30. }
  31. return null;
  32. }
  33. protected override void LoadProperties()
  34. {
  35. base.LoadProperties();
  36. DisableLibrary = GetProperty("DisableLibrary", false);
  37. }
  38. protected override void SaveProperties()
  39. {
  40. base.SaveProperties();
  41. SetProperty("DisableLibrary", DisableLibrary);
  42. }
  43. }
  44. }