浏览代码

If we got the default value use the defaultValue

CPKreuz 1 年之前
父节点
当前提交
cb17bcc7e9

+ 6 - 6
src/PixiEditor.Extensions/Common/UserPreferences/IPreferences.cs

@@ -64,12 +64,12 @@ public interface IPreferences
     public T? GetPreference<T>([SyncedPreferenceConstant] string name);
 
     /// <summary>
-    /// Reads the user preference that is called <paramref name="name"/>, if the setting does not exist the default of <paramref name="fallbackValue"/> will be used
+    /// Reads the user preference that is called <paramref name="name"/>, if the setting does not exist the default of <paramref name="defaultValue"/> will be used
     /// </summary>
     /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
     /// <param name="name">The name of the setting</param>
-    /// <returns>The setting or the <paramref name="fallbackValue"/> if it has not been set yet</returns>
-    public T? GetPreference<T>([SyncedPreferenceConstant] string name, T? fallbackValue);
+    /// <returns>The setting or the <paramref name="defaultValue"/> if it has not been set yet</returns>
+    public T? GetPreference<T>([SyncedPreferenceConstant] string name, T? defaultValue);
 
     /// <summary>
     /// Reads the editor setting that is called <paramref name="name"/>, if the setting does not exist the deafult of <typeparamref name="T"/> will be used
@@ -80,12 +80,12 @@ public interface IPreferences
     public T? GetLocalPreference<T>([LocalPreferenceConstant] string name);
 
     /// <summary>
-    /// Reads the editor setting that is called <paramref name="name"/>, if the setting does not exist the <paramref name="fallbackValue"/> will be used
+    /// Reads the editor setting that is called <paramref name="name"/>, if the setting does not exist the <paramref name="defaultValue"/> will be used
     /// </summary>
     /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
     /// <param name="name">The name of the setting</param>
-    /// <returns>The editor setting or the <paramref name="fallbackValue"/> if it has not been set yet</returns>
-    public T? GetLocalPreference<T>([LocalPreferenceConstant] string name, T? fallbackValue);
+    /// <returns>The editor setting or the <paramref name="defaultValue"/> if it has not been set yet</returns>
+    public T? GetLocalPreference<T>([LocalPreferenceConstant] string name, T? defaultValue);
 
     protected static void SetAsCurrent(IPreferences provider)
     {

+ 10 - 9
src/PixiEditor/Models/Preferences/PreferencesSettings.cs

@@ -150,7 +150,7 @@ internal class PreferencesSettings : IPreferences
         return GetPreference(name, default(T));
     }
 
-    public T? GetPreference<T>(string name, T? fallbackValue)
+    public T? GetPreference<T>(string name, T? defaultValue)
     {
         if (IsLoaded == false)
         {
@@ -159,14 +159,14 @@ internal class PreferencesSettings : IPreferences
 
         try
         {
-            return GetValue(Preferences, name, fallbackValue);
+            return GetValue(Preferences, name, defaultValue);
         }
         catch (InvalidCastException)
         {
             Preferences.Remove(name);
             Save();
 
-            return fallbackValue;
+            return defaultValue;
         }
     }
 
@@ -175,7 +175,7 @@ internal class PreferencesSettings : IPreferences
         return GetLocalPreference(name, default(T));
     }
 
-    public T? GetLocalPreference<T>(string name, T? fallbackValue)
+    public T? GetLocalPreference<T>(string name, T? defaultValue)
     {
         if (IsLoaded == false)
         {
@@ -184,24 +184,25 @@ internal class PreferencesSettings : IPreferences
 
         try
         {
-            return GetValue(LocalPreferences, name, fallbackValue);
+            return GetValue(LocalPreferences, name, defaultValue);
         }
         catch (InvalidCastException)
         {
             LocalPreferences.Remove(name);
             Save();
 
-            return fallbackValue;
+            return defaultValue;
         }
     }
 
-    private T? GetValue<T>(Dictionary<string, object> dict, string name, T? fallbackValue)
+    private T? GetValue<T>(Dictionary<string, object?> dict, string name, T? defaultValue)
     {
-        if (!dict.ContainsKey(name)) return fallbackValue;
+        if (!dict.ContainsKey(name)) return defaultValue;
         var preference = dict[name];
 
         try
         {
+            if (preference == default) return defaultValue;
             if (typeof(T) == preference.GetType()) return (T)preference;
 
             if (typeof(T).IsEnum)
@@ -218,7 +219,7 @@ internal class PreferencesSettings : IPreferences
         }
         catch (Exception)
         {
-            return fallbackValue;
+            return defaultValue;
         }
     }