Browse Source

Fix to property list of AutoEntity interface definitions

Kenric Nugteren 7 months ago
parent
commit
05651cca97
2 changed files with 11 additions and 29 deletions
  1. 3 3
      InABox.Core/CoreUtils.cs
  2. 8 26
      inabox.database.sqlite/SQLiteProvider.cs

+ 3 - 3
InABox.Core/CoreUtils.cs

@@ -842,7 +842,7 @@ namespace InABox.Core
             }
         }
         
-        public static PropertyInfo[] GetInheritedProperties(Type type)
+        public static IEnumerable<PropertyInfo> GetInheritedProperties(Type type)
         {
             if (type.IsInterface)
             {
@@ -874,7 +874,7 @@ namespace InABox.Core
                     propertyInfos.InsertRange(0, newPropertyInfos);
                 }
 
-                return propertyInfos.ToArray();
+                return propertyInfos;
             }
             
             return type.GetProperties(BindingFlags.FlattenHierarchy
@@ -958,7 +958,7 @@ namespace InABox.Core
 
         public static IEnumerable<PropertyInfo> PropertyList(Type T, Func<PropertyInfo, bool> Predicate)
         {
-            return T.GetRuntimeProperties().Where(x => Predicate(x));
+            return (T.IsInterface ? GetInheritedProperties(T) : T.GetRuntimeProperties()).Where(x => Predicate(x));
         }
 
         private static PropertyInfo InternalGetPropertyFromExpression<TObject, TType>(Expression<Func<TObject, TType>> GetPropertyLambda)

+ 8 - 26
inabox.database.sqlite/SQLiteProvider.cs

@@ -641,11 +641,8 @@ public class SQLiteProviderFactory : IProviderFactory
         return "TEXT";
     }
 
-    private void LoadFields(Type type, Dictionary<string, string> fields, List<PropertyInfo>? prefixes, CustomProperty[] customproperties)
+    private void LoadFields(Type type, Dictionary<string, string> fields)
     {
-        if (prefixes == null)
-            prefixes = new List<PropertyInfo>();
-        
         AutoEntity? view = type.GetCustomAttribute<AutoEntity>();
         Type definition = view?.Generator != null
             ? view.Generator.Definition
@@ -794,7 +791,7 @@ public class SQLiteProviderFactory : IProviderFactory
                 else
                 {
                     var type_fields = new Dictionary<string, string>();
-                    LoadFields(view.Generator.Definition, type_fields, null, customproperties);
+                    LoadFields(view.Generator.Definition, type_fields);
 
                     using (var access = MainProvider.GetWriteAccess())
                     {
@@ -808,7 +805,7 @@ public class SQLiteProviderFactory : IProviderFactory
     private Dictionary<string, object?> CheckDefaultColumns(IAutoEntityGenerator generator)
     {
         var viewfields = new Dictionary<string, string>();
-        LoadFields(generator.Definition, viewfields, null, new CustomProperty[] { });
+        LoadFields(generator.Definition, viewfields);
         Dictionary<String, object?> result = new Dictionary<string, object?>();
         if (!viewfields.ContainsKey("ID"))
             result["ID"] = null;
@@ -855,10 +852,10 @@ public class SQLiteProviderFactory : IProviderFactory
                     var constants = CheckDefaultColumns(union);
                     
                     var interfacefields = new Dictionary<string, string>();
-                    LoadFields(union.Definition, interfacefields, null, new CustomProperty[] { });
+                    LoadFields(union.Definition, interfacefields);
                     
                     var entityfields = new Dictionary<string, string>();
-                    LoadFields(table.Entity, entityfields, null, new CustomProperty[] { });
+                    LoadFields(table.Entity, entityfields);
 
                     foreach (var field in interfacefields.Keys)
                     {
@@ -980,7 +977,7 @@ public class SQLiteProviderFactory : IProviderFactory
             var fields = new Dictionary<string, string>();
             var constraints = new List<string>();
             var indexes = new List<string>();
-            LoadFields(type, fields, null, customproperties);
+            LoadFields(type, fields);
             var defs = new List<string>();
             foreach (var key in fields.Keys)
                 defs.Add(string.Format("[{0}] {1}", key, fields[key]));
@@ -1162,13 +1159,10 @@ public class SQLiteProviderFactory : IProviderFactory
 
     private void CheckFields(SQLiteWriteAccessor access, Type type, Dictionary<string, string> current_fields, CustomProperty[] customproperties)
     {
+        var name = type.Name;
         var type_fields = new Dictionary<string, string>();
         var view = type.GetCustomAttribute<AutoEntity>();
-        if ((view != null) && (view.Generator != null))
-            LoadFields(view.Generator.Definition, type_fields, null, customproperties);
-        else
-            LoadFields(type, type_fields, null, customproperties);
-
+        LoadFields(type, type_fields);
 
         var bRebuild = false;
         foreach (var field in type_fields.Keys)
@@ -1243,18 +1237,6 @@ public class SQLiteProviderFactory : IProviderFactory
 //#endif
     }
 
-    // private void CheckViews(SQLiteWriteAccessor access, Type type, Dictionary<String, String> db_views)
-    // {
-    //     var type_view = LoadView(type);
-    //     
-    //     
-    //         if (!type_triggers.Contains(db_triggers[viewname]))
-    //             ExecuteSQL(access, string.Format("DROP TRIGGER {0}", trigger));
-    //     
-    //         if (!db_views.ContainsValue(type_view))
-    //             ExecuteSQL(access, type_view);            
-    // }
-    
     #endregion
 
     private void Log(LogType type, string message)