예제 #1
0
        private static Expression GetLinkOrdering(
            Expression sourceEnumerable,
            ParameterExpression linkParameter,
            Member forwardLink,
            IMemberMapperData mapperData)
        {
            var orderMember =
                mapperData.GetOrderMember(linkParameter.Type) ??
                mapperData.GetIdentifierOrNull(forwardLink.Type)?.MemberInfo;

            if (orderMember == null)
            {
                return(sourceEnumerable);
            }

            var orderMemberAccess = Expression.MakeMemberAccess(
                (orderMember.DeclaringType != linkParameter.Type)
                    ? forwardLink.GetAccess(linkParameter)
                    : linkParameter,
                orderMember);

            return(sourceEnumerable.WithOrderingLinqCall(
                       nameof(Enumerable.OrderBy),
                       linkParameter,
                       orderMemberAccess));
        }