Skip to content

Commit

Permalink
Merge pull request #23 from AndreasReitberger/housekeeping/fix-codefo…
Browse files Browse the repository at this point in the history
…rmatting

[housekeeping] Automated PR to fix formatting errors
  • Loading branch information
AndreasReitberger authored Mar 19, 2024
2 parents 0b9cd25 + 5fbdbd9 commit d6cfbe2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/MauiSettings.Example/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public App()
{
await SettingsApp.LoadSettingsAsync(Hash);
});*/
MainPage = new AppShell();
MainPage = new AppShell();
}

protected override void OnSleep()
Expand Down
8 changes: 4 additions & 4 deletions src/MauiSettings/Helper/MauiSettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static T GetSettingsValue<T>(string key, T defaultValue)
}

public static T ChangeSettingsType<T>(object settingsValue, T defaultValue) => (T)Convert.ChangeType(settingsValue, typeof(T));

// Docs: https://docs.microsoft.com/en-us/dotnet/maui/platform-integration/storage/secure-storage?tabs=ios
// Only string is allowed for secure storage
public static async Task<string> GetSecureSettingsValueAsync(string key, string defaultValue)
Expand Down Expand Up @@ -126,9 +126,9 @@ public static async Task SetSecureSettingsValueAsync(string key, string value)
}

public static void ClearSettings() => Preferences.Clear();

public static void ClearSecureSettings() => SecureStorage.Default.RemoveAll();
#endregion

#endregion
}
}
2 changes: 1 addition & 1 deletion src/MauiSettings/Helper/MauiSettingsObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void SetSettingValue(MemberInfo memberInfo, object settings, objec
{
//throw new NotSupportedException($"MauiSettings: The type '{memberInfo.GetType()}' is not supported for the field: {memberInfo.Name}", exc);
}

}

public static Type GetSettingType(MemberInfo memberInfo)
Expand Down
104 changes: 52 additions & 52 deletions src/MauiSettings/MauiSettingsGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public MauiSettingsGeneric(SO settingsObject, string key)
public static void LoadSettings() => LoadSettings(settings: SettingsObject);

public static void LoadSetting<T>(Expression<Func<SO, T>> value) => LoadObjectSetting(SettingsObject, value);

public static async Task LoadSettingAsync<T>(Expression<Func<SO, T>> value, string? key = null)
{
await Task.Run(async delegate
Expand All @@ -80,138 +80,138 @@ await Task.Run(async delegate
}

public void LoadObjectSettings() => LoadSettings(this);
public static void LoadObjectSetting<T>(object settingsObject, Expression<Func<SO, T>> value)

public static void LoadObjectSetting<T>(object settingsObject, Expression<Func<SO, T>> value)
=> GetExpressionMeta(settings: settingsObject, value, MauiSettingsActions.Load);

public static Task LoadObjectSettingAsync<T>(object settingsObject, Expression<Func<SO, T>> value, string? key = null)
=> Task.Run(async delegate
{
await GetExpressionMetaAsync(settings: settingsObject, value, MauiSettingsActions.Load, key: key);
});

public static void LoadSettings(object settings) => GetClassMeta(settings: settings, mode: MauiSettingsActions.Load, key: null);

public static Task LoadSettingsAsync(string? key = null)
=> Task.Run(async delegate
{
await LoadSettingsAsync(settings: SettingsObject, key: key);
});

public static Task LoadSettingsAsync(object settings, string? key = null)
=> Task.Run(async delegate
{
await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Load, key: key);
});

public static Task LoadSecureSettingsAsync(string? key = null)
=> Task.Run(async delegate
{
await LoadSecureSettingsAsync(settings: SettingsObject, key: key);
});

public static Task LoadSecureSettingsAsync(object settings, string? key = null)
=> Task.Run(async delegate
{
await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Load, secureOnly: true, key: key);
});

public static Task LoadSettingsAsync(Dictionary<string, Tuple<object, Type>> dictionary, bool save = true, string? key = null)
=> Task.Run(async delegate
{
await LoadSettingsAsync(settings: SettingsObject, dictionary: dictionary, save: save, key: key);
});

public static Task LoadSettingsAsync(string key, Tuple<object, Type> data, bool save = true, string? skey = null)
=> Task.Run(async delegate
{
await LoadSettingsAsync(settings: SettingsObject, dictionary: new() { { key, data} }, save: save, key: skey);
await LoadSettingsAsync(settings: SettingsObject, dictionary: new() { { key, data } }, save: save, key: skey);
});
public static Task LoadSettingsAsync(object settings, Dictionary<string, Tuple<object, Type>> dictionary, bool save = true, string? key = null)

public static Task LoadSettingsAsync(object settings, Dictionary<string, Tuple<object, Type>> dictionary, bool save = true, string? key = null)
=> Task.Run(async delegate
{
await GetMetaFromDictionaryAsync(settings: settings, dictionary: dictionary, mode: MauiSettingsActions.Load, secureOnly: false, key: key);
// Save the restored settings right away
if (save) await SaveSettingsAsync(settings: settings, key: key);
});

#endregion

#region SaveSettings
public static void SaveSettings() => SaveSettings(SettingsObject);

public static void SaveSetting<T>(Expression<Func<SO, T>> value) => SaveObjectSetting(SettingsObject, value);
public static void SaveObjectSetting<T>(object settings, Expression<Func<SO, T>> value)

public static void SaveObjectSetting<T>(object settings, Expression<Func<SO, T>> value)
=> GetExpressionMeta(settings, value, MauiSettingsActions.Save);

public void SaveObjectSetting<T>(Expression<Func<SO, T>> value) => SaveObjectSetting(this, value);

public void SaveObjectSettings() => SaveSettings(this);

public static void SaveSettings(object settings) => GetClassMeta(settings, MauiSettingsActions.Save);

public static Task SaveSettingsAsync(string? key = null) => Task.Run(async delegate
{
await SaveSettingsAsync(settings: SettingsObject, key: key);
});

public static Task SaveSettingsAsync(object settings, string? key = null) => Task.Run(async delegate
{
await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Save, key: key);
});

public static Task SaveSecureSettingsAsync(string? key = null) => Task.Run(async delegate
{
await SaveSecureSettingsAsync(settings: SettingsObject, key: key);
});

public static Task SaveSecureSettingsAsync(object settings, string? key = null) => Task.Run(async delegate
{
await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Save, secureOnly: true, key: key);
});

#endregion

#region DeleteSettings
public static void DeleteSettings() => DeleteSettings(SettingsObject);

public static void DeleteSetting<T>(Expression<Func<SO, T>> value) => DeleteObjectSetting(SettingsObject, value);

public void DeleteObjectSetting<T>(Expression<Func<SO, T>> value) => DeleteObjectSetting(this, value);

public static void DeleteObjectSetting<T>(object settings, Expression<Func<SO, T>> value) => GetExpressionMeta(settings, value, MauiSettingsActions.Delete);

public void DeleteObjectSettings() => DeleteSettings(this);

public static void DeleteSettings(object settings) => GetClassMeta(settings, MauiSettingsActions.Delete);

#endregion

#region LoadDefaults
public static void LoadDefaultSettings() => LoadDefaultSettings(SettingsObject);

public static void LoadDefaultSetting<T>(Expression<Func<SO, T>> value) => LoadObjectDefaultSetting(SettingsObject, value);


public void LoadObjectDefaultSetting<T>(Expression<Func<SO, T>> value) => LoadObjectDefaultSetting(this, value);


public static void LoadObjectDefaultSetting<T>(object settings, Expression<Func<SO, T>> value)

public static void LoadObjectDefaultSetting<T>(object settings, Expression<Func<SO, T>> value)
=> GetExpressionMeta(settings, value, MauiSettingsActions.LoadDefaults);

public void LoadObjectDefaultSettings() => LoadDefaultSettings(this);

public static void LoadDefaultSettings(object settings) => GetClassMeta(settings, MauiSettingsActions.LoadDefaults);

#endregion

#region Conversion

public static Task<Dictionary<string, Tuple<object, Type>>> ToDictionaryAsync()
public static Task<Dictionary<string, Tuple<object, Type>>> ToDictionaryAsync()
=> ToDictionaryAsync(settings: SettingsObject);

public static async Task<Dictionary<string, Tuple<object, Type>>> ToDictionaryAsync(object settings)
{
if (true)
Expand Down Expand Up @@ -245,13 +245,13 @@ public static async Task<Dictionary<string, Tuple<object, Type>>> ToDictionaryAs
}
});
*/
return setting;
return setting;
}
}

public static Task<ConcurrentDictionary<string, Tuple<object, Type>>> ToConcurrentDictionaryAsync()
=> ToConcurrentDictionaryAsync(settings: SettingsObject);

public static async Task<ConcurrentDictionary<string, Tuple<object, Type>>> ToConcurrentDictionaryAsync(object settings)
{
ConcurrentDictionary<string, Tuple<object, Type>> setting = new();
Expand Down Expand Up @@ -287,7 +287,7 @@ public static async Task<ConcurrentDictionary<string, Tuple<object, Type>>> ToCo
}

public static Task<Tuple<string, Tuple<object, Type>>> ToSettingsTupleAsync<T>(Expression<Func<SO, T>> value) => ToSettingsTupleAsync(settings: SettingsObject, value: value);

public static async Task<Tuple<string, Tuple<object, Type>>> ToSettingsTupleAsync<T>(object settings, Expression<Func<SO, T>> value)
{
MauiSettingsInfo? info = await GetExpressionMetaAsKeyValuePairAsync(settings: settings, value: value);
Expand Down Expand Up @@ -373,7 +373,7 @@ static async Task GetMetaFromDictionaryAsync(object settings, Dictionary<string,
{
bool useValueFromSettingsInfo = false;
// Try to find the matching key
KeyValuePair<string, Tuple<object, Type>>? keyPair = dictionary?.FirstOrDefault(keypair =>
KeyValuePair<string, Tuple<object, Type>>? keyPair = dictionary?.FirstOrDefault(keypair =>
keypair.Key.EndsWith(mInfo.Name
//?.Replace("get_", string.Empty)
));
Expand Down Expand Up @@ -426,7 +426,7 @@ static async Task GetExpressionMetaAsync<T>(object settings, Expression<Func<SO,
Info = memberExpression.Member,

}, new MauiSettingsInfo(), mode, target, key: key);
}
}
}

static async Task<MauiSettingsInfo?> GetExpressionMetaAsKeyValuePairAsync<T>(object settings, Expression<Func<SO, T>> value, string? key = null)
Expand Down Expand Up @@ -631,7 +631,7 @@ List<MauiSettingAttribute> settingBaseAttributes
if (!secure)
{
// If only secure storage should be loaded, stop here.
if (secureOnly)
if (secureOnly)
return true;
// If the value is not used from the passed settingsInfo, load it

Expand All @@ -649,7 +649,7 @@ List<MauiSettingAttribute> settingBaseAttributes
else
settingsInfo.Value = MauiSettingsHelper.ChangeSettingsType(settingsInfo.Value, settingsInfo.Default);
break;
}
}
}
else if (settingsInfo.SettingsType == typeof(string))
{
Expand Down Expand Up @@ -706,7 +706,7 @@ List<MauiSettingAttribute> settingBaseAttributes
}
// Sets the loaded value back to the settingsObject
MauiSettingsObjectHelper.SetSettingValue(settingsObjectInfo.Info, settingsObjectInfo.OrignalSettingsObject, settingsInfo.Value, settingsInfo.SettingsType);

break;
case MauiSettingsActions.Save:
// Get the value from the settingsObject
Expand All @@ -730,7 +730,7 @@ List<MauiSettingAttribute> settingBaseAttributes
string encryptedString = EncryptionManager.EncryptStringToBase64String(secureString, key);
await MauiSettingsHelper.SetSecureSettingsValueAsync(settingsInfo.Name, encryptedString);
}
else
else
await MauiSettingsHelper.SetSecureSettingsValueAsync(settingsInfo.Name, secureString);
}
else
Expand Down Expand Up @@ -781,7 +781,7 @@ List<MauiSettingAttribute> settingBaseAttributes
string encryptedString = EncryptionManager.EncryptStringToBase64String(secureString, key);
await MauiSettingsHelper.SetSecureSettingsValueAsync(settingsInfo.Name, encryptedString);
}
else
else
await MauiSettingsHelper.SetSecureSettingsValueAsync(settingsInfo.Name, secureString);
}
else
Expand Down Expand Up @@ -823,7 +823,7 @@ List<MauiSettingAttribute> settingBaseAttributes
string encryptedString = EncryptionManager.EncryptStringToBase64String(secureString, key);
await MauiSettingsHelper.SetSecureSettingsValueAsync(settingsInfo.Name, encryptedString);
}
else
else
await MauiSettingsHelper.SetSecureSettingsValueAsync(settingsInfo.Name, secureString);
}
else
Expand Down

0 comments on commit d6cfbe2

Please sign in to comment.