Exemple #1
0
        private bool PropertyExpressionFromIntermediate(MemberExpression node, Expression source,
                                                        out Expression result)
        {
            var init = source as MemberInitExpression;

            if (init?.NewExpression.Arguments.Count == 0)
            {
                foreach (var member in init.Bindings)
                {
                    var assignment = member as MemberAssignment;

                    if (assignment != null)
                    {
                        if (MembersMatch(member.Member, node.Member))
                        {
                            result = assignment.Expression;
                            return(true);
                        }
                    }
                }
            }

            if (strict)
            {
                throw Error.AmbiguousPropertyExpression(node);
            }

            //The root PropertyExpression could have been mapped to any property on this type.
            //We cannot perform any further evaluation, so just leave the expression as is
            //(causing it to be ignored)
            result = node;
            return(true);
        }