|
|
@ -8,7 +8,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ClassAction
|
|
|
|
public class ClassAction
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private static List<Type> initiatedClassTypes = new List<Type>() { };
|
|
|
|
private static Dictionary<Type, DbObject> initiatedClassTypes = new Dictionary<Type, DbObject>() { };
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Initiates the attribute-system and preloads all necessary information<para/>
|
|
|
|
/// Initiates the attribute-system and preloads all necessary information<para/>
|
|
|
|
/// INFO: Will initiate necessary foreignObjects recursively!<para/>
|
|
|
|
/// INFO: Will initiate necessary foreignObjects recursively!<para/>
|
|
|
@ -17,17 +17,22 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|
|
|
/// <param name="classType">The classType to preload</param>
|
|
|
|
/// <param name="classType">The classType to preload</param>
|
|
|
|
/// <returns>DbObject-attribute corresponding to the class</returns>
|
|
|
|
/// <returns>DbObject-attribute corresponding to the class</returns>
|
|
|
|
public static DbObject Init(Type classType)
|
|
|
|
public static DbObject Init(Type classType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DbObject cachedDbObject;
|
|
|
|
|
|
|
|
initiatedClassTypes.TryGetValue(classType, out cachedDbObject);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cachedDbObject == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Check if given class is marked as dbObject
|
|
|
|
// 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'");
|
|
|
|
if (!(classType.GetCustomAttribute(typeof(DbObject), true) is DbObject dbObject)) throw new InvalidOperationException($"Cannot init '{classType.Name}'. Missing Attribute 'DbObject'");
|
|
|
|
|
|
|
|
|
|
|
|
if (!initiatedClassTypes.Contains(classType))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dbObject.Init(classType); // Init 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|