2017-11-29 19:13:38 +01:00
|
|
|
|
using System;
|
2017-12-01 17:59:38 +01:00
|
|
|
|
using Windows.Foundation.Collections;
|
2017-11-29 19:13:38 +01:00
|
|
|
|
using Windows.Storage;
|
2017-12-01 17:59:38 +01:00
|
|
|
|
using ModernKeePass.Interfaces;
|
2017-11-29 19:13:38 +01:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Services
|
|
|
|
|
{
|
2018-02-23 18:09:21 +01:00
|
|
|
|
public class SettingsService : SingletonServiceBase<SettingsService>, ISettingsService
|
2017-11-29 19:13:38 +01:00
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
private readonly IPropertySet _values = ApplicationData.Current.LocalSettings.Values;
|
2018-02-23 18:09:21 +01:00
|
|
|
|
|
2018-03-09 18:06:06 +01:00
|
|
|
|
public T GetSetting<T>(string property, T defaultValue = default(T))
|
2017-11-29 19:13:38 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
return (T)Convert.ChangeType(_values[property], typeof(T));
|
2017-11-29 19:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
catch (InvalidCastException)
|
|
|
|
|
{
|
2018-03-09 18:06:06 +01:00
|
|
|
|
return defaultValue;
|
2017-11-29 19:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-01 17:59:38 +01:00
|
|
|
|
public void PutSetting<T>(string property, T value)
|
2017-11-29 19:13:38 +01:00
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
if (_values.ContainsKey(property))
|
|
|
|
|
_values[property] = value;
|
|
|
|
|
else _values.Add(property, value);
|
2017-11-29 19:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|