Fix getter creation for value type declaring types

This commit is contained in:
root
2026-02-23 21:51:01 +01:00
parent 03b7d06a14
commit 534c998552

View File

@@ -123,18 +123,21 @@ namespace DynamORM.Mapper
private Func<object, object> CreateGetter(PropertyInfo property)
{
if (property == null || !property.CanRead)
return null;
var objParm = Expression.Parameter(typeof(object), "o");
return Expression.Lambda<Func<object, object>>(
Expression.Convert(
Expression.Property(
Expression.TypeAs(objParm, property.DeclaringType),
property.Name),
typeof(object)), objParm).Compile();
}
if (property == null || !property.CanRead)
return null;
var objParm = Expression.Parameter(typeof(object), "o");
var target = property.DeclaringType.IsValueType
? (Expression)Expression.Convert(objParm, property.DeclaringType)
: Expression.TypeAs(objParm, property.DeclaringType);
return Expression.Lambda<Func<object, object>>(
Expression.Convert(
Expression.Property(
target,
property.Name),
typeof(object)), objParm).Compile();
}
private Action<object, object> CreateSetter(PropertyInfo property)
{
@@ -276,4 +279,4 @@ namespace DynamORM.Mapper
#endregion Type command cache
}
}
}