Browse Source

Added system for getting attributes of properties, and fixed filter editor to only list the correct, non-static, serializable properties.

Kenric Nugteren 1 year ago
parent
commit
7462618247

+ 5 - 0
InABox.Core/DatabaseSchema/CustomProperty.cs

@@ -221,6 +221,11 @@ namespace InABox.Core
             return string.IsNullOrWhiteSpace(name) ? null : name;
         }
 
+        public TAttribute? GetAttribute<TAttribute>() where TAttribute : Attribute
+        {
+            return null;
+        }
+
         private void RegenerateEditor()
         {
             Editor = EditorUtils.GetEditor(PropertyType) ?? new NullEditor();

+ 5 - 0
InABox.Core/DatabaseSchema/IProperty.cs

@@ -60,10 +60,15 @@ namespace InABox.Core
         Func<object, object> Getter();
 
         Action<object, object> Setter();
+
+        TAttribute? GetAttribute<TAttribute>() where TAttribute : Attribute;
     }
 
     public static class PropertyExtensions
     {
+        public static bool HasAttribute<TAttribute>(this IProperty property) where TAttribute : Attribute
+            => property.GetAttribute<TAttribute>() != null;
+
         public static IProperty? GetParentWithEditor(this IProperty property)
         {
             if (property.Parent == null) return null;

+ 5 - 0
InABox.Core/DatabaseSchema/StandardProperty.cs

@@ -125,6 +125,11 @@ namespace InABox.Core
             }
         }
 
+        public TAttribute? GetAttribute<TAttribute>() where TAttribute : Attribute
+        {
+            return Property.GetCustomAttribute<TAttribute>();
+        }
+
         public Expression Expression()
         {
             return CoreUtils.CreateMemberExpression(_class, Name);

+ 4 - 1
inabox.wpf/DynamicGrid/Editors/FilterEditor/Nodes/PropertyNode.cs

@@ -22,7 +22,10 @@ public class PropertyNode<T> : ComboBox
         VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
         MinWidth = 100;
 
-        var properties = CoreUtils.PropertyList(typeof(T), x => x.GetCustomAttribute<DoNotSerialize>() == null, true).Keys.ToList();
+        var properties = DatabaseSchema.Properties(typeof(T))
+            .Where(x => !x.HasAttribute<DoNotSerialize>())
+            .Select(x => x.Name)
+            .ToList();
         properties.Sort();
         foreach (var property in properties)
         {