protected override MemberAssignment VisitMemberAssignment(MemberAssignment node)
        {
            if (node.Member is PropertyInfo property)
            {
                if (_mapper.IsTargetType(property.PropertyType))
                {
                    _memberStack.Push(node.Member);
                    var expr = base.VisitMemberAssignment(node);
                    _memberStack.Pop();
                    return(expr);
                }
                else
                {
                    Expression n = _root !;
                    foreach (var member in _memberStack)
                    {
                        n = Expression.PropertyOrField(n, member.Name);
                    }

                    n = Expression.PropertyOrField(n, node.Member.Name);

                    return(Expression.Bind(node.Member, n));
                }
            }

            throw new NotSupportedException($"Member {node.Member} is not supported.");
        }
Beispiel #2
0
        protected override MemberAssignment VisitMemberAssignment(MemberAssignment node)
        {
            // Look for a pattern target.Property = (something)exp; -> mediator.Property = exp
            if (node.Member.MemberType == MemberTypes.Property && _mapper.IsTargetType(node.Member.ReflectedType))
            {
                var        propertyInfo     = (PropertyInfo)node.Member;
                MemberInfo mediatorProperty = _mapper.ConvertToMediator(propertyInfo);

                // Look for a pattern target.Property = (something)exp; -> mediator.Property = exp
                if (node.Expression is UnaryExpression convertExpression &&
                    convertExpression.NodeType == ExpressionType.Convert)
                {
                    return(Expression.Bind(mediatorProperty, Visit(convertExpression.Operand)));
                }

                // No cast, so you can use expression directly
                // TODO: Visit expression
                var visitedTarget = Visit(node.Expression);
                return(Expression.Bind(mediatorProperty, visitedTarget));
            }

            return(base.VisitMemberAssignment(node));
        }