From 0cbffc3f6c8ee02e172bd256bf973f69433548bb Mon Sep 17 00:00:00 2001 From: MBucari Date: Wed, 5 Nov 2025 23:42:31 -0700 Subject: [PATCH] Only allow mocking settings while debugging --- Source/LibationFileManager/Configuration.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/LibationFileManager/Configuration.cs b/Source/LibationFileManager/Configuration.cs index 688e58b9..1fa6ae7d 100644 --- a/Source/LibationFileManager/Configuration.cs +++ b/Source/LibationFileManager/Configuration.cs @@ -60,14 +60,10 @@ namespace LibationFileManager #region singleton stuff - private static readonly Configuration s_SingletonInstance = new(); - public static Configuration Instance { get; private set; } = s_SingletonInstance; +#if !DEBUG public static Configuration CreateMockInstance() { -#if !DEBUG - throw new InvalidOperationException("CreateMockInstance should only be called in design mode."); -#endif var mockInstance = new Configuration() { persistentDictionary = new MockPersistentDictionary() }; mockInstance.SetString("Light", "ThemeVariant"); Instance = mockInstance; @@ -77,6 +73,16 @@ namespace LibationFileManager { Instance = s_SingletonInstance; } + private static readonly Configuration s_SingletonInstance = new(); + public static Configuration Instance { get; private set; } = s_SingletonInstance; +#else + + public static Configuration CreateMockInstance() + => throw new InvalidOperationException($"Can only mock {nameof(Configuration)} in Debug mode."); + public static void RestoreSingletonInstance() + => throw new InvalidOperationException($"Can only mock {nameof(Configuration)} in Debug mode."); + public static Configuration Instance { get; } = new(); +#endif private Configuration() { } #endregion