Browse Source

Remove LambdaExpression.Compile from CompiledBinding.Create (#20996)

pull/21002/head
Julien Lebosquain 2 months ago
committed by GitHub
parent
commit
edb89bd166
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 21
      src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs

21
src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs

@ -303,29 +303,14 @@ internal class BindingExpressionVisitor<TIn>(LambdaExpression expression) : Expr
}
}
private static Func<object, object>? CreateGetter(PropertyInfo info)
private static Func<object, object?>? CreateGetter(PropertyInfo info)
{
if (info.GetMethod == null)
return null;
var target = Expression.Parameter(typeof(object), "target");
return Expression.Lambda<Func<object, object>>(
Expression.Convert(Expression.Call(Expression.Convert(target, info.DeclaringType!), info.GetMethod),
typeof(object)),
target)
.Compile();
return info.CanRead ? info.GetValue : null;
}
private static Action<object, object?>? 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<Action<object, object?>>(
Expression.Call(Expression.Convert(target, info.DeclaringType!), info.SetMethod,
Expression.Convert(value, info.SetMethod.GetParameters()[0].ParameterType)),
target, value)
.Compile();
return info.CanWrite ? info.SetValue : null;
}
private static T GetValue<T>(Expression expr)

Loading…
Cancel
Save