More datahandler stuff, removed SzOperationResult.cs and made a new SzResult.cs and changed Evaluator and DataHander to utilize it
This commit is contained in:
25
SzCore/SZ.cs
25
SzCore/SZ.cs
@@ -10,9 +10,9 @@ public static class SZ
|
||||
|
||||
public static bool IsInitalized { get; private set; } = false;
|
||||
|
||||
public static readonly SzParser SzParser = new();
|
||||
public static readonly SzDataHandler SzDataHandler = new();
|
||||
public static readonly SzEvaluator SzEvaluator = new();
|
||||
public static readonly SzParser Parser = new();
|
||||
public static readonly SzDataHandler DataHandler = new();
|
||||
public static readonly SzEvaluator Evaluator = new();
|
||||
|
||||
public static ISzFileManager LocalFileManager
|
||||
{
|
||||
@@ -44,14 +44,15 @@ public static class SZ
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, object> _services = [];
|
||||
private static readonly List<Type> _protectedServices = [];
|
||||
private static readonly Dictionary<Type, object> Services = [];
|
||||
private static readonly List<Type> ProtectedServices = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initalizes the SZ singleton in SzCore
|
||||
/// </summary>
|
||||
/// <param name="fileManager">An ISzFileManager instance.</param>
|
||||
/// <param name="logger">An ISzLogger instance.</param>
|
||||
/// <param name="databaseHandler">An ISzDatabaseHandler instance</param>
|
||||
/// /// <exception cref="Exception">Throws if SZ has already been initalized</exception>
|
||||
public static void Init(ISzFileManager fileManager, ISzLogger logger, ISzDatabaseHandler databaseHandler)
|
||||
{
|
||||
@@ -96,14 +97,14 @@ public static class SZ
|
||||
{
|
||||
CheckInitialization();
|
||||
|
||||
var result = _services.TryAdd(instance.GetType(), instance);
|
||||
var result = Services.TryAdd(instance.GetType(), instance);
|
||||
if (!result) return false;
|
||||
|
||||
if (isProtected)
|
||||
{
|
||||
if (_protectedServices.Contains(instance.GetType())) return false;
|
||||
if (ProtectedServices.Contains(instance.GetType())) return false;
|
||||
|
||||
_protectedServices.Add(instance.GetType());
|
||||
ProtectedServices.Add(instance.GetType());
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -113,16 +114,16 @@ public static class SZ
|
||||
{
|
||||
CheckInitialization();
|
||||
|
||||
if (!_services.ContainsKey(typeof(T))) return default;
|
||||
return (T)_services[typeof(T)];
|
||||
if (!Services.ContainsKey(typeof(T))) return default;
|
||||
return (T)Services[typeof(T)];
|
||||
}
|
||||
|
||||
public static bool RemoveService<T>()
|
||||
{
|
||||
CheckInitialization();
|
||||
|
||||
if (_protectedServices.Contains(typeof(T))) return false;
|
||||
return _services.Remove(typeof(T));
|
||||
if (ProtectedServices.Contains(typeof(T))) return false;
|
||||
return Services.Remove(typeof(T));
|
||||
}
|
||||
|
||||
private static void CheckInitialization()
|
||||
|
||||
Reference in New Issue
Block a user