From 0dc8f91dc405806cac2c5893f89ea66b4ae4b441 Mon Sep 17 00:00:00 2001 From: Kazuki Ota <117221407+kaota_microsoft@users.noreply.github.com> Date: Fri, 27 Nov 2026 14:06:01 +0900 Subject: [PATCH] Cache DynamicInvoke method metadata Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../Internals/PropertyPathAccessor.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/ReactiveProperty.Core/Internals/PropertyPathAccessor.cs b/Source/ReactiveProperty.Core/Internals/PropertyPathAccessor.cs index eee38908..10e2ba43 100644 --- a/Source/ReactiveProperty.Core/Internals/PropertyPathAccessor.cs +++ b/Source/ReactiveProperty.Core/Internals/PropertyPathAccessor.cs @@ -7,6 +7,9 @@ namespace Reactive.Bindings.Internals; internal static class PropertyPathAccessor { + private static readonly MethodInfo s_dynamicInvokeMethod = typeof(Delegate).GetMethod( + nameof(Delegate.DynamicInvoke), + new[] { typeof(object[]) })!; private static readonly ConditionalWeakTable> s_getters = new(); private static readonly ConditionalWeakTable> s_setters = new(); @@ -21,8 +24,7 @@ internal static class PropertyPathAccessor var invoke = Expression.Invoke(Expression.Constant(accessor), Expression.Convert(source, typeArguments[0])); var fallback = Expression.Call( Expression.Constant(accessor), - nameof(Delegate.DynamicInvoke), - Type.EmptyTypes, + s_dynamicInvokeMethod, Expression.NewArrayInit(typeof(object), source)); var body = Expression.Condition( Expression.TypeIs(source, typeArguments[0]), @@ -42,8 +44,7 @@ internal static class PropertyPathAccessor Expression.Convert(value, typeArguments[1])); var fallback = Expression.Call( Expression.Constant(accessor), - nameof(Delegate.DynamicInvoke), - Type.EmptyTypes, + s_dynamicInvokeMethod, Expression.NewArrayInit(typeof(object), source, value)); var body = Expression.IfThenElse( Expression.AndAlso(Expression.TypeIs(source, typeArguments[0]), Expression.TypeIs(value, typeArguments[1])),