DFLayoutField.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. namespace InABox.Core
  3. {
  4. public interface IDFLayoutField
  5. {
  6. string Name { get; set; }
  7. DFLayoutFieldProperties GetProperties();
  8. }
  9. public abstract class DFLayoutField : DFLayoutControl, IDFLayoutField
  10. {
  11. public DFLayoutField()
  12. {
  13. }
  14. [CodeEditor(Editable = Editable.Disabled)]
  15. [EditorSequence(-999)]
  16. public string Name { get; set; }
  17. protected override string GetDescription()
  18. {
  19. return Name;
  20. }
  21. protected override void LoadProperties()
  22. {
  23. base.LoadProperties();
  24. Name = GetProperty("Name", "");
  25. }
  26. protected override void SaveProperties()
  27. {
  28. base.SaveProperties();
  29. SetProperty("Name", Name);
  30. }
  31. public abstract TValue GetPropertyValue<TValue>(string name);
  32. public abstract DFLayoutFieldProperties GetProperties();
  33. }
  34. public class DFLayoutField<T> : DFLayoutField where T : DFLayoutFieldProperties, new()
  35. {
  36. public DFLayoutField()
  37. {
  38. Properties = new T();
  39. }
  40. public T Properties { get; }
  41. public override DFLayoutFieldProperties GetProperties() => Properties;
  42. public override TValue GetPropertyValue<TValue>(string name)
  43. {
  44. try
  45. {
  46. return (TValue)CoreUtils.GetPropertyValue(Properties, name);
  47. }
  48. catch (Exception)
  49. {
  50. return default;
  51. }
  52. }
  53. }
  54. }