Skip to content

Commit

Permalink
Update MauiSettingsGeneric.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasReitberger committed Jul 16, 2023
1 parent 53ea3bd commit 4b7687d
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/MauiSettings/MauiSettingsGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4b7687d

Please sign in to comment.