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
|
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
public class SettingsService : ISettings
|
2017-11-29 19:13:38 +01:00
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
private readonly IPropertySet _values = ApplicationData.Current.LocalSettings.Values;
|
|
|
|
|
|
|
|
|
|
public T GetSetting<T>(string property)
|
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)
|
|
|
|
|
{
|
|
|
|
|
return default(T);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|