Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba0646f27c | ||
|
|
76922a4039 | ||
|
|
e3869b26c3 |
@@ -71,7 +71,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
|
||||
}
|
||||
catch(InvalidOperationException ex)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot init foreignObject-field '{fi.Name}' of '{classType.Name}'. {ex.Message}", ex);
|
||||
throw new InvalidOperationException($"Cannot init foreignObject-field '{fi.Name}' of '{classType.Name}'. {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
||||
{
|
||||
public class ClassAction
|
||||
{
|
||||
private static List<Type> initiatedClassTypes = new List<Type>() { };
|
||||
private static Dictionary<Type, DbObject> initiatedClassTypes = new Dictionary<Type, DbObject>() { };
|
||||
/// <summary>
|
||||
/// Initiates the attribute-system and preloads all necessary information<para/>
|
||||
/// INFO: Will initiate necessary foreignObjects recursively!<para/>
|
||||
@@ -18,16 +18,21 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
||||
/// <returns>DbObject-attribute corresponding to the class</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<RootNamespace>eu.railduction.netcore.dll.Database_Attribute_System</RootNamespace>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
<Version>1.5.6</Version>
|
||||
<Version>1.5.7</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user