Skip to content

Commit

Permalink
Added LoadSecureSettingAsync method
Browse files Browse the repository at this point in the history
Fixed #24
  • Loading branch information
AndreasReitberger committed Mar 19, 2024
1 parent d6cfbe2 commit af02a8e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/MauiSettings/MauiSettingsGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ public MauiSettingsGeneric(SO settingsObject, string key)

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
public static Task LoadSettingAsync<T>(Expression<Func<SO, T>> value, string? key = null)
=> Task.Run(async delegate
{
await LoadObjectSettingAsync(SettingsObject, value, key: key);
});
}

public static Task LoadSecureSettingAsync<T>(Expression<Func<SO, T>> value, string? key = null)
=> Task.Run(async delegate
{
await LoadSecureObjectSettingAsync(SettingsObject, value, key: key);
});


public void LoadObjectSettings() => LoadSettings(this);

Expand All @@ -89,6 +94,11 @@ public static Task LoadObjectSettingAsync<T>(object settingsObject, Expression<F
{
await GetExpressionMetaAsync(settings: settingsObject, value, MauiSettingsActions.Load, key: key);
});
public static Task LoadSecureObjectSettingAsync<T>(object settingsObject, Expression<Func<SO, T>> value, string? key = null)
=> Task.Run(async delegate
{
await GetExpressionMetaAsync(settings: settingsObject, value, MauiSettingsActions.Load, secureOnly: true, key: key);
});

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

Expand Down Expand Up @@ -307,7 +317,7 @@ public static Task ExhangeKeyAsync(string? newKey = null, string? oldKey = null)
#endregion

#region Private
static List<MemberInfo> GetClassMetaAsList(object settings)
static List<MemberInfo>? GetClassMetaAsList(object settings)
{
lock (lockObject)
{
Expand Down Expand Up @@ -415,7 +425,7 @@ static void GetExpressionMeta<T>(object settings, Expression<Func<SO, T>> value,
}
}

static async Task GetExpressionMetaAsync<T>(object settings, Expression<Func<SO, T>> value, MauiSettingsActions mode, MauiSettingsTarget target = MauiSettingsTarget.Local, string? key = null)
static async Task GetExpressionMetaAsync<T>(object settings, Expression<Func<SO, T>> value, MauiSettingsActions mode, MauiSettingsTarget target = MauiSettingsTarget.Local, bool secureOnly = false, string? key = null)
{

if (value.Body is MemberExpression memberExpression)
Expand All @@ -425,7 +435,7 @@ static async Task GetExpressionMetaAsync<T>(object settings, Expression<Func<SO,
OrignalSettingsObject = settings,
Info = memberExpression.Member,

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

Expand Down

0 comments on commit af02a8e

Please sign in to comment.