diff --git a/Database-Attribute_System/ClassAction.cs b/Database-Attribute_System/ClassAction.cs index 31dd8fe..0775e81 100644 --- a/Database-Attribute_System/ClassAction.cs +++ b/Database-Attribute_System/ClassAction.cs @@ -8,7 +8,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System { public class ClassAction { - private static List initiatedClassTypes = new List() { }; + private static Dictionary initiatedClassTypes = new Dictionary() { }; /// /// Initiates the attribute-system and preloads all necessary information /// INFO: Will initiate necessary foreignObjects recursively! @@ -18,16 +18,21 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System /// DbObject-attribute corresponding to the class public static DbObject Init(Type classType) { - // Check if given class is marked as dbObject - if (!(classType.GetCustomAttribute(typeof(DbObject), true) is DbObject dbObject)) throw new InvalidOperationException($"Cannot init '{classType.Name}'. Missing Attribute 'DbObject'"); + DbObject cachedDbObject; + initiatedClassTypes.TryGetValue(classType, out cachedDbObject); - if (!initiatedClassTypes.Contains(classType)) + if (cachedDbObject == null) { + // Check if given class is marked as dbObject + if (!(classType.GetCustomAttribute(typeof(DbObject), true) is DbObject dbObject)) throw new InvalidOperationException($"Cannot init '{classType.Name}'. Missing Attribute 'DbObject'"); + dbObject.Init(classType); // Init dbObject - initiatedClassTypes.Add(classType); // Set it to the list + initiatedClassTypes.Add(classType, dbObject); // Set it to the list + + cachedDbObject = dbObject; } - return dbObject; + return cachedDbObject; }