mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-21 17:13:09 +08:00
27 lines
906 B
C#
27 lines
906 B
C#
using System.Application.UI.Resx;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
namespace System.Application.UI.ViewModels
|
|
{
|
|
/// <summary>
|
|
/// 本地化、多语言视图模型
|
|
/// </summary>
|
|
public interface ILocalizationViewModel
|
|
{
|
|
public void OnChangeLanguage()
|
|
{
|
|
var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
|
var query = from p in properties
|
|
let attr = p.GetCustomAttribute<ResStringAttribute>()
|
|
where p.PropertyType == typeof(string) && attr != null
|
|
select (p, attr.ResId);
|
|
foreach (var (p, ResId) in query)
|
|
{
|
|
var resId = ResId ?? p.Name;
|
|
var value = AppResources.ResourceManager.GetString(resId);
|
|
p.SetValue(this, value);
|
|
}
|
|
}
|
|
}
|
|
} |