1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
using System.Collections.Generic;
namespace KeePassRPC
{
public abstract class IconCache<T>
{
private static readonly object _iconCacheLock = new object();
private static readonly Dictionary<T, string> _icons = new Dictionary<T, string>();
public static void AddIcon(T iconId, string base64Representation)
{
lock (_iconCacheLock)
{
if (!_icons.ContainsKey(iconId))
_icons.Add(iconId, base64Representation);
}
}
public static string GetIconEncoding(T iconId)
{
lock (_iconCacheLock)
{
string base64Representation;
if (!_icons.TryGetValue(iconId, out base64Representation))
return null;
return base64Representation;
}
}
}
}
|