Browse Source

Added documentation

CPKreuz 1 year ago
parent
commit
0bdcfbef36

+ 5 - 0
src/PixiEditor.Extensions.CommonApi/UserPreferences/Settings/LocalSetting.cs

@@ -1,5 +1,10 @@
 namespace PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 
+/// <summary>
+/// A preference which will only be available on the current device
+/// </summary>
+/// <param name="name">The name of the preference</param>
+/// <param name="fallbackValue">A optional fallback value which will be used if the setting has not been set before</param>
 public class LocalSetting<T>(string name, T? fallbackValue = default) : Setting<T>(name, fallbackValue)
 {
     protected override TAny? GetValue<TAny>(IPreferences preferences, TAny fallbackValue) where TAny : default =>

+ 24 - 0
src/PixiEditor.Extensions.CommonApi/UserPreferences/Settings/Setting.cs

@@ -9,18 +9,32 @@ public abstract class Setting<T> : INotifyPropertyChanged
     private readonly IPreferences preferences;
     private event PropertyChangedEventHandler PropertyChanged;
 
+    /// <summary>
+    /// The name of the preference
+    /// </summary>
     public string Name { get; }
 
+    /// <summary>
+    /// The value of the preference
+    /// </summary>
     public T? Value
     {
         get => GetValue(preferences, FallbackValue);
         set => SetValue(preferences, value);
     }
 
+    /// <summary>
+    /// The value used if the preference has not been set before
+    /// </summary>
     public T? FallbackValue { get; }
 
+    /// <summary>
+    /// Called when the value of the preference has changed
+    /// </summary>
     public event SettingChangedHandler<T> ValueChanged; 
 
+    /// <param name="name">The name of the preference</param>
+    /// <param name="fallbackValue">The value used if the preference has not been set before</param>
     public Setting(string name, T? fallbackValue = default)
     {
         Name = name;
@@ -30,8 +44,18 @@ public abstract class Setting<T> : INotifyPropertyChanged
         preferences.AddCallback<T>(Name, SettingChangeCallback);
     }
 
+    /// <summary>
+    /// Gets the value of the preference or the <see cref="fallbackValue"/> if the preference has not been set before. Note: This will ignore the <see cref="FallbackValue"/> set in the setting constructor
+    /// </summary>
+    /// <param name="fallbackValue">The value used if the preference has not been set before</param>
+    /// <returns>Either the value of the preference or <see cref="fallbackValue"/></returns>
     public T GetValueOrDefault(T fallbackValue) => GetValue(preferences, fallbackValue);
 
+    /// <summary>
+    /// Gets the value of the preference as <typeparamref name="T"/> instead of the type defined by the setting.
+    /// </summary>
+    /// <param name="fallbackValue">The value used if the preference has not been set before</param>
+    /// <returns>Either the value of the preference as <typeparamref name="T"/> or <see cref="fallbackValue"/></returns>
     public T? As<T>(T? fallbackValue = default) => GetValue(preferences, fallbackValue);
 
     protected abstract TAny? GetValue<TAny>(IPreferences preferences, TAny fallbackValue);

+ 5 - 0
src/PixiEditor.Extensions.CommonApi/UserPreferences/Settings/SyncedSetting.cs

@@ -1,5 +1,10 @@
 namespace PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 
+/// <summary>
+/// A preference which may be synced accross multiple devices
+/// </summary>
+/// <param name="name">The name of the preference</param>
+/// <param name="fallbackValue">A optional fallback value which will be used if the setting has not been set before set before</param>
 public class SyncedSetting<T>(string name, T? fallbackValue = default) : Setting<T>(name, fallbackValue)
 {
     protected override TAny? GetValue<TAny>(IPreferences preferences, TAny fallbackValue) where TAny : default =>