mirror of
https://github.com/bitwarden/mobile.git
synced 2025-01-11 19:31:50 +01:00
state service
This commit is contained in:
parent
13a2206735
commit
963b27fd71
11
src/Core/Abstractions/IStateService.cs
Normal file
11
src/Core/Abstractions/IStateService.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Abstractions
|
||||
{
|
||||
public interface IStateService
|
||||
{
|
||||
Task<T> GetAsync<T>(string key);
|
||||
Task RemoveAsync(string key);
|
||||
Task SaveAsync<T>(string key, T obj);
|
||||
}
|
||||
}
|
38
src/Core/Services/StateService.cs
Normal file
38
src/Core/Services/StateService.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Bit.Core.Abstractions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class StateService : IStateService
|
||||
{
|
||||
private readonly Dictionary<string, object> _state = new Dictionary<string, object>();
|
||||
|
||||
public Task<T> GetAsync<T>(string key)
|
||||
{
|
||||
return Task.FromResult(_state.ContainsKey(key) ? (T)_state[key] : (T)(object)null);
|
||||
}
|
||||
|
||||
public Task SaveAsync<T>(string key, T obj)
|
||||
{
|
||||
if(_state.ContainsKey(key))
|
||||
{
|
||||
_state[key] = obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state.Add(key, obj);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task RemoveAsync(string key)
|
||||
{
|
||||
if(_state.ContainsKey(key))
|
||||
{
|
||||
_state.Remove(key);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user