2020-03-24 13:01:14 +01:00
|
|
|
|
using System;
|
|
|
|
|
using Windows.Foundation.Collections;
|
|
|
|
|
using Windows.Storage;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Infrastructure.UWP
|
|
|
|
|
{
|
|
|
|
|
public class UwpSettingsClient : ISettingsProxy
|
|
|
|
|
{
|
|
|
|
|
private readonly IPropertySet _values = ApplicationData.Current.LocalSettings.Values;
|
|
|
|
|
|
2020-03-24 17:31:34 +01:00
|
|
|
|
public T GetSetting<T>(string property, T defaultValue = default(T))
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-04-30 19:40:48 +02:00
|
|
|
|
var value = (T)Convert.ChangeType(_values[property], typeof(T));
|
|
|
|
|
return value == null ? defaultValue : value;
|
2020-03-24 13:01:14 +01:00
|
|
|
|
}
|
|
|
|
|
catch (InvalidCastException)
|
|
|
|
|
{
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PutSetting<T>(string property, T value)
|
|
|
|
|
{
|
|
|
|
|
if (_values.ContainsKey(property))
|
|
|
|
|
_values[property] = value;
|
|
|
|
|
else _values.Add(property, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|