From 4b7687df70e28d654bc921c28f51ca2512fce721 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 16 Jul 2023 17:15:29 +0200 Subject: [PATCH] Update MauiSettingsGeneric.cs --- src/MauiSettings/MauiSettingsGeneric.cs | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) 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(Expression> value) { LoadObjectSetting(SettingsObject, value); } + public static async Task LoadSettingAsync(Expression> value) + { + await Task.Run(async delegate + { + await LoadObjectSettingAsync(SettingsObject, value); + }); + } public void LoadObjectSettings() { LoadSettings(this); @@ -69,6 +76,13 @@ public static void LoadObjectSetting(object settingsObject, Expression(object settingsObject, Expression> 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 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> dictionary, bool save = true) { await Task.Run(async delegate @@ -313,6 +334,16 @@ public static async Task>> ToCo return setting; } + public static async Task>> ToSettingsTupleAsync(Expression> value) + { + return await ToSettingsTupleAsync(settings: SettingsObject, value: value); + } + + public static async Task>> ToSettingsTupleAsync(object settings, Expression> 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(object settings, Expression> value, } } + static async Task GetExpressionMetaAsync(object settings, Expression> 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 GetExpressionMetaAsKeyValuePairAsync(object settings, Expression> 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();