mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-18 23:07:15 -05:00
24 lines
641 B
C#
24 lines
641 B
C#
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace ColorControl.UI.Generics;
|
|
|
|
public static class GeneralExtensions
|
|
{
|
|
public static async ValueTask<TValue?> TryGet<TValue>(this ProtectedBrowserStorage storage, string key, TValue? def = default)
|
|
{
|
|
try
|
|
{
|
|
var result = await storage.GetAsync<TValue>(key);
|
|
var value = result.Success ? result.Value : def;
|
|
|
|
return value;
|
|
}
|
|
catch (CryptographicException)
|
|
{
|
|
await storage.DeleteAsync(key);
|
|
return def;
|
|
}
|
|
}
|
|
}
|