Skip to content

Commit

Permalink
Merge pull request #41 from AndreasReitberger/40-update-dependencies
Browse files Browse the repository at this point in the history
Updated `nugets`
  • Loading branch information
AndreasReitberger authored Apr 3, 2024
2 parents bedba89 + cd93ce6 commit 2e35cd1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 78 deletions.
9 changes: 9 additions & 0 deletions cleanup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Set-ExecutionPolicy Unrestricted
$ErrorActionPreference = "Stop"

# Set current directory to script directory
Set-Location -Path $PSScriptRoot
#Get-ChildItem .\ -include bin,obj -Recurse | format-table
#pause
cls
Get-ChildItem .\ -include bin,obj -Recurse | ForEach-Object ($_) { Remove-Item $_.FullName -Force -Recurse }
2 changes: 1 addition & 1 deletion src/MauiSettings/MauiSettings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.14" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.14" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SharedNetCoreLibrary" Version="1.1.4" />
<PackageReference Include="SharedNetCoreLibrary" Version="1.1.6" />
</ItemGroup>

</Project>
137 changes: 60 additions & 77 deletions src/MauiSettings/MauiSettingsGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public static SO SettingsObject
{
get
{
if (_settingsObject == null)
{
_settingsObject = new SO();
}
_settingsObject ??= new SO();
return (SO)_settingsObject;
}
}
Expand Down Expand Up @@ -69,36 +66,31 @@ public MauiSettingsGeneric(SO settingsObject, string settingsKey)

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

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 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);

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 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 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 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);
public static void LoadSettings(object settings) => GetClassMeta(settings: settings, mode: MauiSettingsActions.Load);

public static Task LoadSettingsAsync(string? key = null)
=> Task.Run(async delegate
Expand Down Expand Up @@ -277,7 +269,8 @@ public static async Task<ConcurrentDictionary<string, Tuple<object, Type>>> ToCo
return setting;
}

public static Task<Tuple<string, Tuple<object, Type>>> ToSettingsTupleAsync<T>(Expression<Func<SO, T>> value) => ToSettingsTupleAsync(settings: SettingsObject, value: value);
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)
{
Expand Down Expand Up @@ -311,7 +304,7 @@ public static Task ExhangeKeyAsync(string newKey, string? oldKey = null)
return declaredMembers?.ToList();
}
}
static void GetClassMeta(object settings, MauiSettingsActions mode, MauiSettingsTarget target = MauiSettingsTarget.Local, string? key = null)
static void GetClassMeta(object settings, MauiSettingsActions mode, MauiSettingsTarget target = MauiSettingsTarget.Local)
{
lock (lockObject)
{
Expand All @@ -332,63 +325,55 @@ static void GetClassMeta(object settings, MauiSettingsActions mode, MauiSettings
}
static async Task GetClassMetaAsync(object settings, MauiSettingsActions mode, MauiSettingsTarget target = MauiSettingsTarget.Local, bool secureOnly = false, string? key = null)
{
//lock (lockObject)
if (true)
{
// Get all member infos from the passed settingsObject
IEnumerable<MemberInfo> declaredMembers = settings.GetType().GetTypeInfo().DeclaredMembers;
// Get all member infos from the passed settingsObject
IEnumerable<MemberInfo> declaredMembers = settings.GetType().GetTypeInfo().DeclaredMembers;

MauiSettingsMemberInfo settingsObjectInfo = new();
MauiSettingsInfo settingsInfo = new();
MauiSettingsMemberInfo settingsObjectInfo = new();
MauiSettingsInfo settingsInfo = new();

foreach (MemberInfo mInfo in declaredMembers)
{
settingsObjectInfo.OrignalSettingsObject = settings;
settingsObjectInfo.Info = mInfo;
// Handles saving the settings to the Maui.Storage.Preferences
_ = await ProcessSettingsInfoAsync(settingsObjectInfo, settingsInfo, mode, target, secureOnly: secureOnly, key: key);
}
}
foreach (MemberInfo mInfo in declaredMembers)
{
settingsObjectInfo.OrignalSettingsObject = settings;
settingsObjectInfo.Info = mInfo;
// Handles saving the settings to the Maui.Storage.Preferences
_ = await ProcessSettingsInfoAsync(settingsObjectInfo, settingsInfo, mode, target, secureOnly: secureOnly, key: key);
}
}
static async Task GetMetaFromDictionaryAsync(object settings, Dictionary<string, Tuple<object, Type>> dictionary, MauiSettingsActions mode, MauiSettingsTarget target = MauiSettingsTarget.Local, bool secureOnly = false, string? key = null)
{
//lock (lockObject)
if (true)
{
// Get all member infos from the passed settingsObject
IEnumerable<MemberInfo> declaredMembers = settings.GetType().GetTypeInfo().DeclaredMembers;
// Get all member infos from the passed settingsObject
IEnumerable<MemberInfo> declaredMembers = settings.GetType().GetTypeInfo().DeclaredMembers;

MauiSettingsMemberInfo settingsObjectInfo = new();
MauiSettingsInfo settingsInfo = new();
MauiSettingsMemberInfo settingsObjectInfo = new();
MauiSettingsInfo settingsInfo = new();

foreach (MemberInfo mInfo in declaredMembers)
foreach (MemberInfo mInfo in declaredMembers)
{
bool useValueFromSettingsInfo = false;
// Try to find the matching settingsKey
KeyValuePair<string, Tuple<object, Type>>? keyPair = dictionary?.FirstOrDefault(keypair =>
keypair.Key.EndsWith(mInfo.Name
//?.Replace("get_", string.Empty)
));
if (keyPair?.Key != null)
{
bool useValueFromSettingsInfo = false;
// Try to find the matching settingsKey
KeyValuePair<string, Tuple<object, Type>>? keyPair = dictionary?.FirstOrDefault(keypair =>
keypair.Key.EndsWith(mInfo.Name
//?.Replace("get_", string.Empty)
));
if (keyPair?.Key != null)
useValueFromSettingsInfo = true;
// If a matching settingsKey was found, prepare the settingsInfo with the loaded data
settingsInfo = new()
{
useValueFromSettingsInfo = true;
// If a matching settingsKey was found, prepare the settingsInfo with the loaded data
settingsInfo = new()
{
Name = mInfo.Name?.Replace("get_", string.Empty),
Value = keyPair.Value.Value.Item1,
SettingsType = keyPair.Value.Value.Item2,
};
}
else
useValueFromSettingsInfo = false;
settingsObjectInfo.OrignalSettingsObject = settings;
settingsObjectInfo.Info = mInfo;
// Handles saving the settings to the Maui.Storage.Preferences
_ = await ProcessSettingsInfoAsync(
settingsObjectInfo, settingsInfo, mode, target, secureOnly: secureOnly, useValueFromSettingsInfo: useValueFromSettingsInfo, key: key);
Name = mInfo.Name?.Replace("get_", string.Empty),
Value = keyPair.Value.Value.Item1,
SettingsType = keyPair.Value.Value.Item2,
};
}
}
else
useValueFromSettingsInfo = false;
settingsObjectInfo.OrignalSettingsObject = settings;
settingsObjectInfo.Info = mInfo;
// Handles saving the settings to the Maui.Storage.Preferences
_ = await ProcessSettingsInfoAsync(
settingsObjectInfo, settingsInfo, mode, target, secureOnly: secureOnly, useValueFromSettingsInfo: useValueFromSettingsInfo, key: key);
}
}

static void GetExpressionMeta<T>(object settings, Expression<Func<SO, T>> value, MauiSettingsActions mode, MauiSettingsTarget target = MauiSettingsTarget.Local)
Expand Down Expand Up @@ -884,8 +869,6 @@ List<MauiSettingAttribute> settingBaseAttributes
throw new InvalidDataException($"Only data type of '{typeof(string)}' is allowed for secure storage!");
}
}
// Sets the loaded value back to the settingsObject
//MauiSettingsObjectHelper.SetSettingValue(settingsObjectInfo.Info, settingsObjectInfo.OrignalSettingsObject, settingsInfo.Value, settingsInfo.SettingsType);
return settingsInfo;
}

Expand Down
6 changes: 6 additions & 0 deletions src/restore.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
echo off

echo "Restore..."
dotnet restore

pause

0 comments on commit 2e35cd1

Please sign in to comment.