Browse Source

Added recursive checks for Standard property DoNotSerialize and DoNotPersist attributes
Added ability to add summaries to Custom Properties

frogsoftware 11 months ago
parent
commit
86d86bccfa

+ 102 - 81
InABox.Core/DatabaseSchema/CustomProperty.cs

@@ -26,46 +26,9 @@ namespace InABox.Core
         private string _page;
         private bool _visible;
         private bool _editable;
-
-        protected override void Init()
-        {
-            base.Init();
-
-            Visible = true;
-            Editable = true;
-            Required = false;
-            HasEditor = true;
-            Editor = new NullEditor();
-        }
-
-        [MemoEditor(Visible = Core.Visible.Default)]
-        [EditorSequence(5)]
-        public string Comment { get; set; }
-
-        [CheckBoxEditor(Visible = Core.Visible.Default)]
-        [EditorSequence(8)]
-        public bool Visible
-        {
-            get => _visible;
-            set
-            {
-                _visible = value;
-                RegenerateEditor();
-            }
-        }
-
-        [CheckBoxEditor(Visible = Core.Visible.Optional)]
-        [EditorSequence(9)]
-        public bool Editable
-        {
-            get => _editable;
-            set
-            {
-                _editable = value;
-                RegenerateEditor();
-            }
-        }
-
+        
+        private Summary _summary;
+        
         [ComboLookupEditor(typeof(PropertyClassLookups))]
         [EditorSequence(1)]
         public string Class
@@ -77,19 +40,7 @@ namespace InABox.Core
                 CheckExpressions();
             }
         }
-
-        [DoNotPersist]
-        [DoNotSerialize]
-        public Type? ClassType
-        {
-            get => _class;
-            set
-            {
-                _class = value;
-                CheckExpressions();
-            }
-        }
-
+        
         [EditorSequence(2)]
         public string Name
         {
@@ -127,7 +78,103 @@ namespace InABox.Core
                 RegenerateEditor();
             }
         }
+        
+        [MemoEditor(Visible = Core.Visible.Default)]
+        [EditorSequence(4)]
+        public string Comment { get; set; }
+        
+        [TextBoxEditor(Visible = Core.Visible.Optional)]
+        [EditorSequence(5)]
+        public string Caption
+        {
+            get => _caption;
+            set
+            {
+                _caption = value;
+                RegenerateEditor();
+            }
+        }
+
+        [TextBoxEditor(Visible = Core.Visible.Optional)]
+        [EditorSequence(6)]
+        public string Page
+        {
+            get => _page;
+            set
+            {
+                _page = value;
+                RegenerateEditor();
+            }
+        }
+
+        [CheckBoxEditor(Visible = Core.Visible.Optional)]
+        [EditorSequence(7)]
+        public bool Required { get; set; }
+
+        [CheckBoxEditor(Visible = Core.Visible.Default)]
+        [EditorSequence(8)]
+        public bool Visible
+        {
+            get => _visible;
+            set
+            {
+                _visible = value;
+                RegenerateEditor();
+            }
+        }
+
+        [CheckBoxEditor(Visible = Core.Visible.Optional)]
+        [EditorSequence(9)]
+        public bool Editable
+        {
+            get => _editable;
+            set
+            {
+                _editable = value;
+                RegenerateEditor();
+            }
+        }
+
+        [EnumLookupEditor(typeof(Summary))]
+        [EditorSequence(10)]
+        public Summary Summary
+        {
+            get => _summary;
+            set
+            {
+                _summary = value;
+                RegenerateEditor();
+            }
+        }
+
+
+        protected override void Init()
+        {
+            base.Init();
+
+            Visible = true;
+            Editable = true;
+            Required = false;
+            HasEditor = true;
+            Editor = new NullEditor();
+            _summary = Summary.None;
+        }
+
+        
+
 
+        [DoNotPersist]
+        [DoNotSerialize]
+        public Type? ClassType
+        {
+            get => _class;
+            set
+            {
+                _class = value;
+                CheckExpressions();
+            }
+        }
+        
         [DoNotPersist]
         [DoNotSerialize]
         public Type PropertyType
@@ -156,36 +203,9 @@ namespace InABox.Core
         [DoNotSerialize]
         public bool HasEditor { get; set; }
 
-        [TextBoxEditor(Visible = Core.Visible.Optional)]
-        [EditorSequence(6)]
-        public string Caption
-        {
-            get => _caption;
-            set
-            {
-                _caption = value;
-                RegenerateEditor();
-            }
-        }
-
-        [TextBoxEditor(Visible = Core.Visible.Optional)]
-        [EditorSequence(7)]
-        public string Page
-        {
-            get => _page;
-            set
-            {
-                _page = value;
-                RegenerateEditor();
-            }
-        }
-
-        [CheckBoxEditor(Visible = Core.Visible.Optional)]
-        [EditorSequence(8)]
-        public bool Required { get; set; }
+        
 
         [NullEditor]
-        [EditorSequence(9)]
         public LoggablePropertyAttribute? Loggable { get; set; }
 
         [NullEditor]
@@ -247,6 +267,7 @@ namespace InABox.Core
             Editor.Page = Page;
             Editor.Editable = Editable ? Core.Editable.Enabled : Core.Editable.Disabled;
             Editor.Visible = Visible ? Core.Visible.Optional : Core.Visible.Hidden;
+            Editor.Summary = Summary;
         }
 
         public Expression Expression()

+ 10 - 1
InABox.Core/DatabaseSchema/StandardProperty.cs

@@ -149,6 +149,15 @@ namespace InABox.Core
             }
         }
 
+        private bool IsPersistable(StandardProperty? prop)
+        {
+            if (prop == null)
+                return true;
+            if (prop.Property.GetCustomAttribute<DoNotPersist>() != null)
+                return false;
+            return IsPersistable(prop.Parent as StandardProperty);
+        }
+        
         private bool? _dbColumn;
         public bool IsDBColumn
         {
@@ -157,7 +166,7 @@ namespace InABox.Core
                 if (!_dbColumn.HasValue)
                 {
                     _dbColumn = !IsCalculated
-                        && Property.GetCustomAttribute<DoNotPersist>() == null
+                        && IsPersistable(this)
                         && Property.CanWrite;
                 }
                 return _dbColumn.Value;

+ 11 - 2
InABox.Core/Serialization.cs

@@ -645,11 +645,20 @@ namespace InABox.Core
         {
             var result = ReadBinaryValue(reader, typeof(T));
             return (result != null ? (T)result : default)!;
-        } 
+        }
+
+        private static bool IsSerializable(Type type,  StandardProperty? prop)
+        {
+            if (prop == null)
+                return true;
+            if (prop.Property.GetCustomAttribute<DoNotSerialize>() != null)
+                return false;
+            return IsSerializable(type, prop.Parent as StandardProperty);
+        }
         
         public static IEnumerable<IProperty> SerializableProperties(Type type) =>
             DatabaseSchema.Properties(type)
-                .Where(x => !(x is StandardProperty st) || st.Property.GetCustomAttribute<DoNotSerialize>() == null);
+                .Where(x => !(x is StandardProperty st) || IsSerializable(type,st));
 
         private static void GetOriginalValues(BaseObject obj, string? parent, List<Tuple<Type, string, object?>> values)
         {