Files
modernkeepass/ModernKeePass.Infrastructure/UWP/UwpSettingsClient.cs
Geoffroy BONNEVILLE 7e44d47065 WIP Clean Architecture
Windows 8.1 App Uses keepasslib v2.44 (temporarily)
2020-03-24 13:01:14 +01:00

32 lines
882 B
C#

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;
public T GetSetting<T>(string property, T defaultValue = default)
{
try
{
return (T)Convert.ChangeType(_values[property], typeof(T));
}
catch (InvalidCastException)
{
return defaultValue;
}
}
public void PutSetting<T>(string property, T value)
{
if (_values.ContainsKey(property))
_values[property] = value;
else _values.Add(property, value);
}
}
}