DFLayoutField.cs 1.6 KB

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