diff --git a/src/MauiSettings/MauiSettingsGeneric.cs b/src/MauiSettings/MauiSettingsGeneric.cs index 451a394..9d41341 100644 --- a/src/MauiSettings/MauiSettingsGeneric.cs +++ b/src/MauiSettings/MauiSettingsGeneric.cs @@ -61,6 +61,13 @@ public static void LoadSetting<T>(Expression<Func<SO, T>> value) { LoadObjectSetting(SettingsObject, value); } + public static async Task LoadSettingAsync<T>(Expression<Func<SO, T>> value) + { + await Task.Run(async delegate + { + await LoadObjectSettingAsync(SettingsObject, value); + }); + } public void LoadObjectSettings() { LoadSettings(this); @@ -69,6 +76,13 @@ public static void LoadObjectSetting<T>(object settingsObject, Expression<Func<S { GetExpressionMeta(settings: settingsObject, value, MauiSettingsActions.Load); } + public static async Task LoadObjectSettingAsync<T>(object settingsObject, Expression<Func<SO, T>> value) + { + await Task.Run(async delegate + { + await GetExpressionMetaAsync(settings: settingsObject, value, MauiSettingsActions.Load); + }); + } public static void LoadSettings(object settings) { GetClassMeta(settings: settings, mode: MauiSettingsActions.Load); @@ -108,6 +122,13 @@ await Task.Run(async delegate await LoadSettingsAsync(settings: SettingsObject, dictionary: dictionary, save: save); }); } + public static async Task LoadSettingsAsync(string key, Tuple<object, Type> data, bool save = true) + { + await Task.Run(async delegate + { + await LoadSettingsAsync(settings: SettingsObject, dictionary: new() { { key, data} }, save: save); + }); + } public static async Task LoadSettingsAsync(object settings, Dictionary<string, Tuple<object, Type>> dictionary, bool save = true) { await Task.Run(async delegate @@ -313,6 +334,16 @@ public static async Task<ConcurrentDictionary<string, Tuple<object, Type>>> ToCo return setting; } + public static async Task<Tuple<string, Tuple<object, Type>>> ToSettingsTupleAsync<T>(Expression<Func<SO, T>> value) + { + return await 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); + return new(info.Name, new(info.Value, info.SettingsType)); + } #endregion #region Private @@ -423,6 +454,34 @@ 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) + { + + if (value.Body is MemberExpression memberExpression) + { + _ = await ProcessSettingsInfoAsync(new MauiSettingsMemberInfo() + { + OrignalSettingsObject = settings, + Info = memberExpression.Member, + + }, new MauiSettingsInfo(), mode, target); + } + } + + static async Task<MauiSettingsInfo> GetExpressionMetaAsKeyValuePairAsync<T>(object settings, Expression<Func<SO, T>> value) + { + if (value.Body is MemberExpression memberExpression) + { + return await ProcessSettingsInfoAsKeyValuePairAsync(new MauiSettingsMemberInfo() + { + OrignalSettingsObject = settings, + Info = memberExpression.Member, + + }, new MauiSettingsInfo()); + } + return new(); + } + static bool ProcessSettingsInfo(MauiSettingsMemberInfo settingsObjectInfo, MauiSettingsInfo settingsInfo, MauiSettingsActions mode, MauiSettingsTarget target, bool throwOnError = false) { settingsInfo ??= new();