Files
Libation/Source/LibationFileManager/Configuration.cs
Michael Bucari-Tovo d67692355f Enable project-wide nullable reference types
Added DB migration for nullable types.
2026-02-05 12:43:05 -07:00

43 lines
1.2 KiB
C#

using Dinah.Core;
#if !DEBUG
using System.Linq;
#endif
namespace LibationFileManager;
public partial class Configuration : PropertyChangeFilter
{
#region singleton stuff
public static Configuration CreateMockInstance()
{
#if !DEBUG
if (!new System.Diagnostics.StackTrace().GetFrames().Select(f => f.GetMethod()?.DeclaringType?.Assembly.GetName().Name).Any(f => f?.EndsWith(".Tests") ?? false))
throw new System.InvalidOperationException($"Can only mock {nameof(Configuration)} in Debug mode or in test assemblies.");
#endif
var mockInstance = new Configuration() { JsonBackedDictionary = new EphemeralDictionary() };
mockInstance.SetString("Light", "ThemeVariant");
Instance = mockInstance;
return mockInstance;
}
public static void RestoreSingletonInstance()
{
Instance = s_SingletonInstance;
}
private static readonly Configuration s_SingletonInstance = new();
public static Configuration Instance { get; private set; } = s_SingletonInstance;
public bool IsEphemeralInstance => JsonBackedDictionary is EphemeralDictionary;
public Configuration CreateEphemeralCopy()
{
var copy = new Configuration();
copy.LoadEphemeralSettings(Settings.GetJObject());
return copy;
}
private Configuration() { }
#endregion
}