| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Linq; |
| using System.Text; |
| using System.Text; |
| using System.Threading.Tasks; |
| using System.Threading.Tasks; |
| using System.Windows; |
| using System.Windows; |
| |
| |
| namespace Playnite.SDK |
| namespace Playnite.SDK |
| { |
| { |
| /// <summary> |
| /// <summary> |
. | |
| /// Describes application resource provider. |
| |
| /// </summary> |
| |
| public interface IResourceProvider |
| |
| { |
| |
| /// <summary> |
| |
| /// Gets string resource. |
| |
| /// </summary> |
| |
| /// <param name="key">Resource key.</param> |
| |
| /// <returns>String resource.</returns> |
| |
| string GetString(string key); |
| |
| |
| |
| /// <summary> |
| |
| /// Gets application resource. |
| |
| /// </summary> |
| |
| /// <param name="key">Resource key.</param> |
| |
| /// <returns>Application resource.</returns> |
| |
| object GetResource(string key); |
| |
| } |
| |
| |
| |
| /// <summary> |
| /// Represents default resource provider. |
| /// Represents default resource provider. |
| /// </summary> |
| /// </summary> |
| public class ResourceProvider : IResourceProvider |
| public class ResourceProvider : IResourceProvider |
| { |
| { |
| /// <summary> |
| /// <summary> |
| /// Creates new instance of <see cref="ResourceProvider"/>. |
| /// Creates new instance of <see cref="ResourceProvider"/>. |
| /// </summary> |
| /// </summary> |
| public ResourceProvider() |
| public ResourceProvider() |
| { |
| { |
| } |
| } |
| |
| |
| string IResourceProvider.GetString(string key) |
| string IResourceProvider.GetString(string key) |
| { |
| { |
| return GetString(key); |
| return GetString(key); |
| } |
| } |
| |
| |
| object IResourceProvider.GetResource(string key) |
| object IResourceProvider.GetResource(string key) |
| { |
| { |
| return GetResource(key); |
| return GetResource(key); |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets string resource. |
| /// Gets string resource. |
| /// </summary> |
| /// </summary> |
| /// <param name="key">String resource key.</param> |
| /// <param name="key">String resource key.</param> |
| /// <returns>String resource.</returns> |
| /// <returns>String resource.</returns> |
| public static string GetString(string key) |
| public static string GetString(string key) |
| { |
| { |
| var resource = Application.Current?.TryFindResource(key); |
| var resource = Application.Current?.TryFindResource(key); |
| return resource == null ? $"<!{key}!>" : resource as string; |
| return resource == null ? $"<!{key}!>" : resource as string; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
| /// Gets application resource. |
| /// Gets application resource. |
| /// </summary> |
| /// </summary> |
| /// <param name="key">Resource key.</param> |
| /// <param name="key">Resource key.</param> |
| /// <returns>Application resource.</returns> |
| /// <returns>Application resource.</returns> |
| public static object GetResource(string key) |
| public static object GetResource(string key) |
| { |
| { |
| return Application.Current?.TryFindResource(key); |
| return Application.Current?.TryFindResource(key); |
. | |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <typeparam name="T"></typeparam> |
| |
| /// <param name="key"></param> |
| |
| /// <returns></returns> |
| |
| public static T GetResource<T>(string key) |
| |
| { |
| |
| return (T)Application.Current?.TryFindResource(key); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |