Files
VDownload/VDownload.Services/VDownload.Services.UI/VDownload.Services.UI.DictionaryResources/DictionaryResourcesService.cs

51 lines
965 B
C#
Raw Normal View History

using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Services.UI.DictionaryResources
{
public interface IDictionaryResourcesService
{
2024-03-12 00:16:21 +01:00
ResourceDictionary Resources { get; set; }
T Get<T>(string key);
}
public class DictionaryResourcesService : IDictionaryResourcesService
{
2024-03-12 00:16:21 +01:00
#region PROPERTIES
public ResourceDictionary Resources { get; set; }
#endregion
#region CONSTRUCTORS
public DictionaryResourcesService() { }
#endregion
#region PUBLIC METHODS
public T Get<T>(string key)
{
2024-03-12 00:16:21 +01:00
Resources.TryGetValue(key, out object value);
if (value is not null && value is T cast)
{
return cast;
}
throw new KeyNotFoundException();
}
#endregion
}
}