/// <summary>
        /// 获取排序表达式树
        /// </summary>
        /// <param name="propertySource">属性名</param>
        /// <returns></returns>
        public LambdaExpression GetSortedExpression(string propertySource)
        {
            var exp = PropertiesMapping.Find(x => GetPropertyInfo(x.Item2).Name == propertySource);
            if (exp == null)
            {
                throw new PropertyNoExistException(propertySource, TargetType);
            }

            // 更改参数
            var visitor = new MapperExpressionVisitor(paramClassSource);
            var result = visitor.Visit(exp.Item1);
            return Expression.Lambda(result, paramClassSource);
        }
        internal Expression GetLambdaDest(string propertyName)
        {
            var exp = PropertiesMapping.Find(x => GetPropertyInfo(x.Item1).Name == propertyName);
            if (exp != null)
            {
                var final = exp.Item2;
                if (final.NodeType == ExpressionType.Convert)
                {
                    final = (final as UnaryExpression).Operand;
                }

                return final;
            }

            return null;
        }
Beispiel #3
0
        internal LambdaExpression GetSortedExpression(string propertySource)
        {
            Contract.Requires(!string.IsNullOrEmpty(propertySource));
            Expression result = null;
            var        exp    = PropertiesMapping.Find(x => GetPropertyInfo(x.Item2).Name == propertySource);

            if (exp == null)
            {
                throw new PropertyNoExistException(propertySource, TargetType);
            }
            // To change the parameter.
            var visitor = new MapperExpressionVisitor(paramClassSource);

            result = visitor.Visit(exp.Item1);
            return(Expression.Lambda(result, paramClassSource));
        }