···11111212namespace osu.Framework.Configuration
1313{
1414- public abstract class ConfigManager<T> : ITrackableConfigManager, IDisposable
1515- where T : struct
1414+ public abstract class ConfigManager<TLookup> : ITrackableConfigManager, IDisposable
1515+ where TLookup : struct, Enum
1616 {
1717 /// <summary>
1818 /// Whether user specified configuration elements should be set even though a default was never specified.
1919 /// </summary>
2020 protected virtual bool AddMissingEntries => true;
21212222- private readonly IDictionary<T, object> defaultOverrides;
2222+ private readonly IDictionary<TLookup, object> defaultOverrides;
23232424- protected readonly Dictionary<T, IBindable> ConfigStore = new Dictionary<T, IBindable>();
2424+ protected readonly Dictionary<TLookup, IBindable> ConfigStore = new Dictionary<TLookup, IBindable>();
25252626 /// <summary>
2727- /// Initialise a new <see cref="ConfigManager{T}"/>
2727+ /// Initialise a new <see cref="ConfigManager{TLookup}"/>
2828 /// </summary>
2929- /// <param name="defaultOverrides">Dictionary of overrides which should take precedence over defaults specified by the <see cref="ConfigManager{T}"/> implementation.</param>
3030- protected ConfigManager(IDictionary<T, object> defaultOverrides = null)
2929+ /// <param name="defaultOverrides">Dictionary of overrides which should take precedence over defaults specified by the <see cref="ConfigManager{TLookup}"/> implementation.</param>
3030+ protected ConfigManager(IDictionary<TLookup, object> defaultOverrides = null)
3131 {
3232 this.defaultOverrides = defaultOverrides;
3333 }
···4040 {
4141 }
42424343- public BindableDouble Set(T lookup, double value, double? min = null, double? max = null, double? precision = null)
4343+ public BindableDouble Set(TLookup lookup, double value, double? min = null, double? max = null, double? precision = null)
4444 {
4545 value = getDefault(lookup, value);
4646···6262 return bindable;
6363 }
64646565- public BindableFloat Set(T lookup, float value, float? min = null, float? max = null, float? precision = null)
6565+ public BindableFloat Set(TLookup lookup, float value, float? min = null, float? max = null, float? precision = null)
6666 {
6767 value = getDefault(lookup, value);
6868···8484 return bindable;
8585 }
86868787- public BindableInt Set(T lookup, int value, int? min = null, int? max = null)
8787+ public BindableInt Set(TLookup lookup, int value, int? min = null, int? max = null)
8888 {
8989 value = getDefault(lookup, value);
9090···105105 return bindable;
106106 }
107107108108- public BindableBool Set(T lookup, bool value)
108108+ public BindableBool Set(TLookup lookup, bool value)
109109 {
110110 value = getDefault(lookup, value);
111111···124124 return bindable;
125125 }
126126127127- public BindableSize Set(T lookup, Size value, Size? min = null, Size? max = null)
127127+ public BindableSize Set(TLookup lookup, Size value, Size? min = null, Size? max = null)
128128 {
129129 value = getDefault(lookup, value);
130130···145145 return bindable;
146146 }
147147148148- public Bindable<U> Set<U>(T lookup, U value)
148148+ public Bindable<TValue> Set<TValue>(TLookup lookup, TValue value)
149149 {
150150 value = getDefault(lookup, value);
151151152152- Bindable<U> bindable = GetOriginalBindable<U>(lookup);
152152+ Bindable<TValue> bindable = GetOriginalBindable<TValue>(lookup);
153153154154 if (bindable == null)
155155 bindable = set(lookup, value);
···161161 return bindable;
162162 }
163163164164- protected virtual void AddBindable<TBindable>(T lookup, Bindable<TBindable> bindable)
164164+ protected virtual void AddBindable<TBindable>(TLookup lookup, Bindable<TBindable> bindable)
165165 {
166166 ConfigStore[lookup] = bindable;
167167 bindable.ValueChanged += _ => backgroundSave();
168168 }
169169170170- private TType getDefault<TType>(T lookup, TType fallback)
170170+ private TValue getDefault<TValue>(TLookup lookup, TValue fallback)
171171 {
172172 if (defaultOverrides != null && defaultOverrides.TryGetValue(lookup, out object found))
173173- return (TType)found;
173173+ return (TValue)found;
174174175175 return fallback;
176176 }
177177178178- private Bindable<U> set<U>(T lookup, U value)
178178+ private Bindable<TValue> set<TValue>(TLookup lookup, TValue value)
179179 {
180180- Bindable<U> bindable = new Bindable<U>(value);
180180+ Bindable<TValue> bindable = new Bindable<TValue>(value);
181181 AddBindable(lookup, bindable);
182182 return bindable;
183183 }
184184185185- public U Get<U>(T lookup) => GetOriginalBindable<U>(lookup).Value;
185185+ public TValue Get<TValue>(TLookup lookup) => GetOriginalBindable<TValue>(lookup).Value;
186186187187- protected Bindable<U> GetOriginalBindable<U>(T lookup)
187187+ protected Bindable<TValue> GetOriginalBindable<TValue>(TLookup lookup)
188188 {
189189 if (ConfigStore.TryGetValue(lookup, out IBindable obj))
190190 {
191191- if (!(obj is Bindable<U>))
192192- throw new InvalidCastException($"Cannot convert bindable of type {obj.GetType()} retrieved from {nameof(ConfigManager<T>)} to {typeof(Bindable<U>)}.");
191191+ if (!(obj is Bindable<TValue>))
192192+ throw new InvalidCastException($"Cannot convert bindable of type {obj.GetType()} retrieved from {nameof(ConfigManager<TLookup>)} to {typeof(Bindable<TValue>)}.");
193193194194- return (Bindable<U>)obj;
194194+ return (Bindable<TValue>)obj;
195195 }
196196197197 return null;
···203203 /// a local reference.
204204 /// </summary>
205205 /// <returns>A weakly bound copy of the specified bindable.</returns>
206206- public Bindable<U> GetBindable<U>(T lookup) => GetOriginalBindable<U>(lookup)?.GetBoundCopy();
206206+ public Bindable<TValue> GetBindable<TValue>(TLookup lookup) => GetOriginalBindable<TValue>(lookup)?.GetBoundCopy();
207207208208 /// <summary>
209209 /// Binds a local bindable with a configuration-backed bindable.
210210 /// </summary>
211211- public void BindWith<U>(T lookup, Bindable<U> bindable) => bindable.BindTo(GetOriginalBindable<U>(lookup));
211211+ public void BindWith<TValue>(TLookup lookup, Bindable<TValue> bindable) => bindable.BindTo(GetOriginalBindable<TValue>(lookup));
212212213213 #region IDisposable Support
214214···240240241241 public void LoadInto(TrackedSettings settings) => settings.LoadFrom(this);
242242243243- public class TrackedSetting<U> : Tracking.TrackedSetting<U>
243243+ public class TrackedSetting<TValue> : Tracking.TrackedSetting<TValue>
244244 {
245245 /// <summary>
246246- /// Constructs a new <see cref="TrackedSetting{U}"/>.
246246+ /// Constructs a new <see cref="TrackedSetting{TValue}"/>.
247247 /// </summary>
248248 /// <param name="setting">The config setting to be tracked.</param>
249249 /// <param name="generateDescription">A function that generates the description for the setting, invoked every time the value changes.</param>
250250- public TrackedSetting(T setting, Func<U, SettingDescription> generateDescription)
250250+ public TrackedSetting(TLookup setting, Func<TValue, SettingDescription> generateDescription)
251251 : base(setting, generateDescription)
252252 {
253253 }
+4-4
osu.Framework/Configuration/IniConfigManager.cs
···10101111namespace osu.Framework.Configuration
1212{
1313- public class IniConfigManager<T> : ConfigManager<T>
1414- where T : struct
1313+ public class IniConfigManager<TLookup> : ConfigManager<TLookup>
1414+ where TLookup : struct, Enum
1515 {
1616 /// <summary>
1717 /// The backing file used to store the config. Null means no persistent storage.
···20202121 private readonly Storage storage;
22222323- public IniConfigManager(Storage storage, IDictionary<T, object> defaultOverrides = null)
2323+ public IniConfigManager(Storage storage, IDictionary<TLookup, object> defaultOverrides = null)
2424 : base(defaultOverrides)
2525 {
2626 this.storage = storage;
···5151 string key = line.Substring(0, equalsIndex).Trim();
5252 string val = line.Remove(0, equalsIndex + 1).Trim();
53535454- if (!Enum.TryParse(key, out T lookup))
5454+ if (!Enum.TryParse(key, out TLookup lookup))
5555 continue;
56565757 if (ConfigStore.TryGetValue(lookup, out IBindable b))
···1010 {
1111 public event Action<SettingDescription> SettingChanged;
12121313- public void LoadFrom<T>(ConfigManager<T> configManager)
1414- where T : struct
1313+ public void LoadFrom<TLookup>(ConfigManager<TLookup> configManager)
1414+ where TLookup : struct, Enum
1515 {
1616 foreach (var value in this)
1717 {