From 8493faf9c07e55518a23b420bc02a2bbfc5427e3 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Thu, 1 Aug 2024 23:01:15 +0200 Subject: [PATCH] Remove System.Linq.Expressions usages in ReflectionClrPropertyInfo (#16568) --- .../Data/Core/ClrPropertyInfo.cs | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs b/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs index 6027676501..66a36c99d6 100644 --- a/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs +++ b/src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs @@ -1,5 +1,4 @@ using System; -using System.Linq.Expressions; using System.Reflection; namespace Avalonia.Data.Core @@ -40,35 +39,19 @@ namespace Avalonia.Data.Core public class ReflectionClrPropertyInfo : ClrPropertyInfo { - static Action? CreateSetter(PropertyInfo info) - { - if (info.SetMethod == null) - return null; - var target = Expression.Parameter(typeof(object), "target"); - var value = Expression.Parameter(typeof(object), "value"); - return Expression.Lambda>( - Expression.Call(Expression.Convert(target, info.DeclaringType!), info.SetMethod, - Expression.Convert(value, info.SetMethod.GetParameters()[0].ParameterType)), - target, value) - .Compile(); - } - - static Func? CreateGetter(PropertyInfo info) - { - if (info.GetMethod == null) - return null; - var target = Expression.Parameter(typeof(object), "target"); - return Expression.Lambda>( - Expression.Convert(Expression.Call(Expression.Convert(target, info.DeclaringType!), info.GetMethod), - typeof(object)), - target) - .Compile(); - } + private static Action? CreateSetter(PropertyInfo info) + => info.SetMethod is { } setMethod ? + (target, value) => setMethod.Invoke(target, [value]) : + null; + + private static Func? CreateGetter(PropertyInfo info) + => info.GetMethod is { } getMethod ? + target => getMethod.Invoke(target, []) : + null; public ReflectionClrPropertyInfo(PropertyInfo info) : base(info.Name, CreateGetter(info), CreateSetter(info), info.PropertyType) { - } } }