From d6bc0de7857dd5290687be4777ca6bf163d693d9 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Mon, 18 Sep 2023 20:20:59 +0000 Subject: [PATCH] use compiled bidning for localizations (#5684) --- .../Common/Locale/LocaleExtension.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Ava/Common/Locale/LocaleExtension.cs b/src/Ryujinx.Ava/Common/Locale/LocaleExtension.cs index cd1c1510..8d345ae0 100644 --- a/src/Ryujinx.Ava/Common/Locale/LocaleExtension.cs +++ b/src/Ryujinx.Ava/Common/Locale/LocaleExtension.cs @@ -1,6 +1,7 @@ -using Avalonia.Data; +using Avalonia.Data.Core; using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml.MarkupExtensions; +using Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings; using System; namespace Ryujinx.Ava.Common.Locale @@ -18,11 +19,20 @@ namespace Ryujinx.Ava.Common.Locale { LocaleKeys keyToUse = Key; - ReflectionBindingExtension binding = new($"[{keyToUse}]") - { - Mode = BindingMode.OneWay, - Source = LocaleManager.Instance, - }; + var builder = new CompiledBindingPathBuilder(); + + builder.SetRawSource(LocaleManager.Instance) + .Property(new ClrPropertyInfo("Item", + obj => (LocaleManager.Instance[keyToUse]), + null, + typeof(string)), (weakRef, iPropInfo) => + { + return PropertyInfoAccessorFactory.CreateInpcPropertyAccessor(weakRef, iPropInfo); + }); + + var path = builder.Build(); + + var binding = new CompiledBindingExtension(path); return binding.ProvideValue(serviceProvider); }