예제 #1
0
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.NodeType == ExpressionType.Constant)
            {
                return(base.VisitMember(node));
            }

            string sourcePath = null;

            ParameterExpression parameterExpression = node.GetParameterExpression();
            Type sType = parameterExpression == null ? null : parameterExpression.Type;

            if (sType != null && sType == this.CurrentParameterType && node.IsMemberExpression())
            {
                sourcePath = node.GetPropertyFullName();
            }
            else
            {
                return(base.VisitMember(node));
            }

            string fullName = string.IsNullOrEmpty(this.ParentFullName)
                            ? sourcePath
                            : string.Concat(this.ParentFullName, ".", sourcePath);

            MemberExpression me = this.NewParameter.BuildExpression(fullName);

            return(me);
        }
예제 #2
0
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.NodeType == ExpressionType.Constant)
            {
                return(base.VisitMember(node));
            }

            string sourcePath;

            var parameterExpression = node.GetParameterExpression();
            var sType = parameterExpression?.Type;

            if (sType != null && sType == CurrentParameterType && node.IsMemberExpression())
            {
                sourcePath = node.GetPropertyFullName();
            }
            else
            {
                return(base.VisitMember(node));
            }

            var fullName = string.IsNullOrEmpty(ParentFullName)
                            ? sourcePath
                            : string.Concat(ParentFullName, ".", sourcePath);

            var me = ExpressionFactory.MemberAccesses(fullName, NewParameter);

            return(me);
        }
        protected override Expression VisitMember(MemberExpression node)
        {
            var parameterExpression = node.GetParameterExpression();

            if (parameterExpression == null)
            {
                var baseExpression = node.GetBaseOfMemberExpression();
                if (baseExpression?.NodeType == ExpressionType.Constant)
                {
                    return(this.Visit
                           (
                               Expression.Constant
                               (
                                   GetConstantValue
                                   (
                                       ((ConstantExpression)baseExpression).Value,
                                       node.GetPropertyFullName(),
                                       baseExpression.Type
                                   ),
                                   node.Type
                               )
                           ));
                }

                return(base.VisitMember(node));
            }

            InfoDictionary.Add(parameterExpression, TypeMappings);
            return(GetMappedMemberExpression(node.GetBaseOfMemberExpression(), new List <PropertyMapInfo>()));

            Expression GetMappedMemberExpression(Expression parentExpression, List <PropertyMapInfo> propertyMapInfoList)
            {
                Expression mappedParentExpression = this.Visit(parentExpression);

                FindDestinationFullName(parentExpression.Type, mappedParentExpression.Type, node.GetPropertyFullName(), propertyMapInfoList);

                if (propertyMapInfoList.Any(x => x.CustomExpression != null))
                {
                    var fromCustomExpression = GetMemberExpressionFromCustomExpression
                                               (
                        propertyMapInfoList,
                        propertyMapInfoList.Last(x => x.CustomExpression != null),
                        mappedParentExpression
                                               );

                    this.TypeMappings.AddTypeMapping(ConfigurationProvider, node.Type, fromCustomExpression.Type);
                    return(fromCustomExpression);
                }

                var memberExpression = GetMemberExpressionFromMemberMaps(BuildFullName(propertyMapInfoList), mappedParentExpression);

                this.TypeMappings.AddTypeMapping(ConfigurationProvider, node.Type, memberExpression.Type);

                return(memberExpression);
            }
        }
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.NodeType == ExpressionType.Constant)
            {
                return(base.VisitMember(node));
            }

            if (!object.ReferenceEquals(CurrentParameter, node.GetParameterExpression()) || !node.IsMemberExpression())
            {
                return(base.VisitMember(node));
            }

            return(ExpressionHelpers.MemberAccesses
                   (
                       string.IsNullOrEmpty(ParentFullName)
                        ? node.GetPropertyFullName()
                        : $"{ParentFullName}.{node.GetPropertyFullName()}",
                       NewParameter
                   ));
        }
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.NodeType == ExpressionType.Constant)
            {
                return(base.VisitMember(node));
            }

            string sourcePath;

            var parameterExpression = node.GetParameterExpression();

            if (parameterExpression == null)
            {
                return(base.VisitMember(node));
            }

            InfoDictionary.Add(parameterExpression, TypeMappings);

            var sType = parameterExpression.Type;

            if (InfoDictionary.ContainsKey(parameterExpression) && node.IsMemberExpression())
            {
                sourcePath = node.GetPropertyFullName();
            }
            else
            {
                return(base.VisitMember(node));
            }

            var propertyMapInfoList = new List <PropertyMapInfo>();

            FindDestinationFullName(sType, InfoDictionary[parameterExpression].DestType, sourcePath, propertyMapInfoList);
            string fullName;

            if (propertyMapInfoList.Any(x => x.CustomExpression != null))
            {
                var last = propertyMapInfoList.Last(x => x.CustomExpression != null);
                var beforeCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) =>
                {
                    if (propertyMapInfoList.IndexOf(next) < propertyMapInfoList.IndexOf(last))
                    {
                        list.Add(next);
                    }
                    return(list);
                });

                var afterCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) =>
                {
                    if (propertyMapInfoList.IndexOf(next) > propertyMapInfoList.IndexOf(last))
                    {
                        list.Add(next);
                    }
                    return(list);
                });

                fullName = BuildFullName(beforeCustExpression);
                var visitor = new PrependParentNameVisitor(last.CustomExpression.Parameters[0].Type /*Parent type of current property*/, fullName, InfoDictionary[parameterExpression].NewParameter);

                var ex = propertyMapInfoList[propertyMapInfoList.Count - 1] != last
                    ? visitor.Visit(last.CustomExpression.Body.AddExpressions(afterCustExpression))
                    : visitor.Visit(last.CustomExpression.Body);

                return(ex);
            }
            fullName = BuildFullName(propertyMapInfoList);
            var me = InfoDictionary[parameterExpression].NewParameter.BuildExpression(fullName);

            return(me);
        }
예제 #6
0
        protected override Expression VisitMember(MemberExpression node)
        {
            string sourcePath;

            var parameterExpression = node.GetParameterExpression();

            if (parameterExpression == null)
            {
                return(base.VisitMember(node));
            }

            InfoDictionary.Add(parameterExpression, TypeMappings);
            var sType = parameterExpression.Type;

            if (sType != null && InfoDictionary.ContainsKey(parameterExpression) && node.IsMemberExpression())
            {
                sourcePath = node.GetPropertyFullName();
            }
            else
            {
                return(base.VisitMember(node));
            }

            var propertyMapInfoList = new List <PropertyMapInfo>();

            FindDestinationFullName(sType, InfoDictionary[parameterExpression].DestType, sourcePath, propertyMapInfoList);
            string fullName;

            if (propertyMapInfoList.Any(x => x.CustomExpression != null))//CustomExpression takes precedence over DestinationPropertyInfo
            {
                var last = propertyMapInfoList.Last(x => x.CustomExpression != null);
                var beforeCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) =>
                {
                    if (propertyMapInfoList.IndexOf(next) < propertyMapInfoList.IndexOf(last))
                    {
                        list.Add(next);
                    }
                    return(list);
                });

                var afterCustExpression = propertyMapInfoList.Aggregate(new List <PropertyMapInfo>(), (list, next) =>
                {
                    if (propertyMapInfoList.IndexOf(next) > propertyMapInfoList.IndexOf(last))
                    {
                        list.Add(next);
                    }
                    return(list);
                });


                fullName = BuildFullName(beforeCustExpression);

                var visitor = new PrependParentNameVisitor(last.CustomExpression.Parameters[0].Type /*Parent type of current property*/, fullName, InfoDictionary[parameterExpression].NewParameter);

                var ex = propertyMapInfoList[propertyMapInfoList.Count - 1] != last
                    ? visitor.Visit(last.CustomExpression.Body.MemberAccesses(afterCustExpression))
                    : visitor.Visit(last.CustomExpression.Body);

                var v = new FindMemberExpressionsVisitor(InfoDictionary[parameterExpression].NewParameter);
                v.Visit(ex);

                return(v.Result);
            }
            fullName = BuildFullName(propertyMapInfoList);
            var me = ExpressionFactory.MemberAccesses(fullName, InfoDictionary[parameterExpression].NewParameter);

            if (me.Expression.NodeType == ExpressionType.MemberAccess && (me.Type == typeof(string) || me.Type.GetTypeInfo().IsValueType || (me.Type.GetTypeInfo().IsGenericType &&
                                                                                                                                             me.Type.GetGenericTypeDefinition() == typeof(Nullable <>) &&
                                                                                                                                             Nullable.GetUnderlyingType(me.Type).GetTypeInfo().IsValueType)))
            {
                return(me.Expression);
            }

            return(me);
        }
예제 #7
0
        protected override Expression VisitMember(MemberExpression node)
        {
            var parameterExpression = node.GetParameterExpression();

            if (parameterExpression == null)
            {
                return(base.VisitMember(node));
            }

            InfoDictionary.Add(parameterExpression, TypeMappings);
            return(GetMappedMemberExpression(node.GetBaseOfMemberExpression(), new List <PropertyMapInfo>()));

            Expression GetMappedMemberExpression(Expression parentExpression, List <PropertyMapInfo> propertyMapInfoList)
            {
                Expression mappedParentExpression = this.Visit(parentExpression);

                FindDestinationFullName(parentExpression.Type, mappedParentExpression.Type, node.GetPropertyFullName(), propertyMapInfoList);

                if (propertyMapInfoList.Any(x => x.CustomExpression != null))//CustomExpression takes precedence over DestinationPropertyInfo
                {
                    return(GetMemberExpression
                           (
                               new FindMemberExpressionsVisitor(mappedParentExpression),
                               GetMemberExpressionFromCustomExpression
                               (
                                   propertyMapInfoList,
                                   propertyMapInfoList.Last(x => x.CustomExpression != null),
                                   mappedParentExpression
                               )
                           ));
                }

                return(GetExpressionForInclude
                       (
                           GetMemberExpressionFromMemberMaps
                           (
                               BuildFullName(propertyMapInfoList),
                               mappedParentExpression
                           )
                       ));
            }

            Expression GetExpressionForInclude(MemberExpression memberExpression)
            => memberExpression.Type.IsLiteralType() ? memberExpression.Expression : memberExpression;

            MemberExpression GetMemberExpression(FindMemberExpressionsVisitor visitor, Expression mappedExpression)
            {
                visitor.Visit(mappedExpression);
                return(visitor.Result);
            }
        }