Пример #1
0
        public static Expression ParseToBody(Expression expression, ParameterExpression p)
        {
            MapExpressionVisitor mapExpressionVisitor = new MapExpressionVisitor();

            mapExpressionVisitor._p = p;
            return(mapExpressionVisitor.Visit(expression));
        }
Пример #2
0
        public static Expression ParseToBody(Expression expression)
        {
            MapExpressionVisitor mapExpressionVisitor = new MapExpressionVisitor();

            mapExpressionVisitor._type = null;
            return(mapExpressionVisitor.Visit(expression));
        }
Пример #3
0
        /// <summary>
        /// 定义规则
        /// </summary>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="tOut">返回<see cref="TOut"/> 属性或字段</param>
        /// <param name="from">用于生成<see cref="TOut"/>列的规则 </param>
        /// <returns></returns>
        public Map <TIn, TOut> DefineRule <TValue>(Expression <Func <TOut, TValue> > tOut, Expression <Func <TIn, TValue> > from)
        {
            var name = tOut.GetPropertyOrFieldName();

            //不同的处理结果处理
            if (!_dict_rule.ContainsKey(name))
            {
                _dict_rule.Add(name, MapExpressionVisitor.ParseToBody(from, _parameterExpression));
            }
            else
            {
                if (_dict_rule.Remove(name))
                {
                    _dict_rule.Add(name, MapExpressionVisitor.ParseToBody(from, _parameterExpression));
                }
            }
            return(this);
        }