From e30eb0cde65fea0fe76ed1370c70b30c4e142645 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 21 Jan 2020 09:42:45 -0600 Subject: [PATCH] break off settings methods from config to extension methods --- BizHawk.Client.Common/config/Config.cs | 66 +----------------- .../config/ConfigExtensions.cs | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 BizHawk.Client.Common/config/ConfigExtensions.cs diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 8f462d6084..5a40a931c7 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using BizHawk.Common; -using BizHawk.Emulation.Common; // ReSharper disable FieldCanBeMadeReadOnly.Global // ReSharper disable InconsistentNaming @@ -279,73 +278,10 @@ namespace BizHawk.Client.Common public int GifWriterDelay = -1; public bool VideoWriterAudioSync = true; - #region emulation core settings - + // Emulation core settings public Dictionary CoreSettings = new Dictionary(); public Dictionary CoreSyncSettings = new Dictionary(); - public object GetCoreSettings() - where T : IEmulator - { - return GetCoreSettings(typeof(T)); - } - - public object GetCoreSettings(Type t) - { - CoreSettings.TryGetValue(t.ToString(), out var ret); - return ret; - } - - public void PutCoreSettings(object o) - where T : IEmulator - { - PutCoreSettings(o, typeof(T)); - } - - public void PutCoreSettings(object o, Type t) - { - if (o != null) - { - CoreSettings[t.ToString()] = o; - } - else - { - CoreSettings.Remove(t.ToString()); - } - } - - public object GetCoreSyncSettings() - where T : IEmulator - { - return GetCoreSyncSettings(typeof(T)); - } - - public object GetCoreSyncSettings(Type t) - { - CoreSyncSettings.TryGetValue(t.ToString(), out var ret); - return ret; - } - - public void PutCoreSyncSettings(object o) - where T : IEmulator - { - PutCoreSyncSettings(o, typeof(T)); - } - - public void PutCoreSyncSettings(object o, Type t) - { - if (o != null) - { - CoreSyncSettings[t.ToString()] = o; - } - else - { - CoreSyncSettings.Remove(t.ToString()); - } - } - - #endregion - public Dictionary CommonToolSettings = new Dictionary(); public Dictionary> CustomToolSettings = new Dictionary>(); diff --git a/BizHawk.Client.Common/config/ConfigExtensions.cs b/BizHawk.Client.Common/config/ConfigExtensions.cs new file mode 100644 index 0000000000..f5532a2f49 --- /dev/null +++ b/BizHawk.Client.Common/config/ConfigExtensions.cs @@ -0,0 +1,68 @@ +using System; +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.Common +{ + public static class ConfigExtensions + { + public static object GetCoreSettings(this Config config, Type t) + { + config.CoreSettings.TryGetValue(t.ToString(), out var ret); + return ret; + } + + public static object GetCoreSettings(this Config config) + where T : IEmulator + { + return config.GetCoreSettings(typeof(T)); + } + + public static void PutCoreSettings(this Config config, object o, Type t) + { + if (o != null) + { + config.CoreSettings[t.ToString()] = o; + } + else + { + config.CoreSettings.Remove(t.ToString()); + } + } + + public static void PutCoreSettings(this Config config, object o) + where T : IEmulator + { + config.PutCoreSettings(o, typeof(T)); + } + + public static object GetCoreSyncSettings(this Config config) + where T : IEmulator + { + return config.GetCoreSyncSettings(typeof(T)); + } + + public static object GetCoreSyncSettings(this Config config, Type t) + { + config.CoreSyncSettings.TryGetValue(t.ToString(), out var ret); + return ret; + } + + public static void PutCoreSyncSettings(this Config config, object o, Type t) + { + if (o != null) + { + config.CoreSyncSettings[t.ToString()] = o; + } + else + { + config.CoreSyncSettings.Remove(t.ToString()); + } + } + + public static void PutCoreSyncSettings(this Config config, object o) + where T : IEmulator + { + config.PutCoreSyncSettings(o, typeof(T)); + } + } +}