protected override PropertyAccessResult AccessMember(Expression entity, Type entityType, string propertyName)
        {
            var propertyInfo = entityType.GetProperty(propertyName);

            if (propertyInfo == null)
            {
                return(null);
            }

            var propertyAccess = Expression.MakeMemberAccess(entity, propertyInfo);

            var result = new PropertyAccessResult(
                propertyType: propertyInfo.PropertyType,
                propertyAccessExpression: propertyAccess);

            return(result);
        }
Exemplo n.º 2
0
        public PropertyAccessResult Decorate(PropertyAccessResult propertyAccess)
        {
            if (!typeof(DateTime).IsAssignableFrom(propertyAccess.PropertyType))
            {
                return(propertyAccess);
            }

            Func <DateTime?, DateTime?> parserFunc = EntityFunctions.TruncateTime;

            var castedExpression = Expression.Convert(propertyAccess.PropertyAccessExpression, typeof(DateTime?));

            var decoratedPropertyExpression = Expression.Call(parserFunc.Method, castedExpression);

            var result = Expression.Convert(decoratedPropertyExpression, typeof(DateTime));

            return(new PropertyAccessResult(
                       propertyType: typeof(DateTime),
                       propertyAccessExpression: result));
        }