mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-19 00:51:30 -07:00
25 lines
888 B
C#
25 lines
888 B
C#
using System.Resources;
|
|
|
|
namespace Bloxstrap.Extensions
|
|
{
|
|
static class ResourceManagerEx
|
|
{
|
|
/// <summary>
|
|
/// Returns the value of the specified string resource. <br/>
|
|
/// If the resource is not found, the resource name will be returned.
|
|
/// </summary>
|
|
public static string GetStringSafe(this ResourceManager manager, string name) => manager.GetStringSafe(name, null);
|
|
|
|
/// <summary>
|
|
/// Returns the value of the string resource localized for the specified culture. <br/>
|
|
/// If the resource is not found, the resource name will be returned.
|
|
/// </summary>
|
|
public static string GetStringSafe(this ResourceManager manager, string name, CultureInfo? culture)
|
|
{
|
|
string? resourceValue = manager.GetString(name, culture);
|
|
|
|
return resourceValue ?? name;
|
|
}
|
|
}
|
|
}
|