Example #1
0
        internal override Expression VisitMemberInit(MemberInitExpression init)
        {
            MemberAssignmentAnalysis previous = null;

            foreach (MemberBinding binding in init.Bindings)
            {
                MemberAssignment memberAssignment = binding as MemberAssignment;
                if (memberAssignment != null)
                {
                    MemberAssignmentAnalysis memberAssignmentAnalysis = Analyze(entity, memberAssignment.Expression);
                    if (memberAssignmentAnalysis.MultiplePathsFound)
                    {
                        multiplePathsFound = true;
                        return(init);
                    }
                    Exception ex = memberAssignmentAnalysis.CheckCompatibleAssignments(init.Type, ref previous);
                    if (ex != null)
                    {
                        incompatibleAssignmentsException = ex;
                        return(init);
                    }
                    if (pathFromEntity.Count == 0)
                    {
                        pathFromEntity.AddRange(memberAssignmentAnalysis.GetExpressionsToTargetEntity());
                    }
                }
            }
            return(init);
        }
Example #2
0
        internal static MemberAssignmentAnalysis Analyze(Expression entityInScope, Expression assignmentExpression)
        {
            MemberAssignmentAnalysis memberAssignmentAnalysis = new MemberAssignmentAnalysis(entityInScope);

            memberAssignmentAnalysis.Visit(assignmentExpression);
            return(memberAssignmentAnalysis);
        }
Example #3
0
 internal Exception CheckCompatibleAssignments(Type targetType, ref MemberAssignmentAnalysis previous)
 {
     if (previous == null)
     {
         previous = this;
         return(null);
     }
     Expression[] expressionsToTargetEntity  = previous.GetExpressionsToTargetEntity();
     Expression[] expressionsToTargetEntity2 = GetExpressionsToTargetEntity();
     return(CheckCompatibleAssignments(targetType, expressionsToTargetEntity, expressionsToTargetEntity2));
 }
Example #4
0
            internal static void Analyze(MemberInitExpression mie, PathBox pb)
            {
                EntityProjectionAnalyzer entityProjectionAnalyzer = new EntityProjectionAnalyzer(pb, mie.Type);
                MemberAssignmentAnalysis previous = null;

                foreach (MemberBinding binding in mie.Bindings)
                {
                    MemberAssignment memberAssignment = binding as MemberAssignment;
                    entityProjectionAnalyzer.Visit(memberAssignment.Expression);
                    if (memberAssignment != null)
                    {
                        MemberAssignmentAnalysis memberAssignmentAnalysis = MemberAssignmentAnalysis.Analyze(pb.ParamExpressionInScope, memberAssignment.Expression);
                        if (memberAssignmentAnalysis.IncompatibleAssignmentsException != null)
                        {
                            throw memberAssignmentAnalysis.IncompatibleAssignmentsException;
                        }
                        Type         memberType = GetMemberType(memberAssignment.Member);
                        Expression[] expressionsBeyondTargetEntity = memberAssignmentAnalysis.GetExpressionsBeyondTargetEntity();
                        if (expressionsBeyondTargetEntity.Length == 0)
                        {
                            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", memberType, memberAssignment.Expression));
                        }
                        MemberExpression memberExpression = expressionsBeyondTargetEntity[expressionsBeyondTargetEntity.Length - 1] as MemberExpression;
                        if (memberExpression != null && memberExpression.Member.Name != memberAssignment.Member.Name)
                        {
                            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Cannot assign the value from the {0} property to the {1} property.  When projecting results into a entity type, the property names of the source type and the target type must match for the properties being projected.", memberExpression.Member.Name, memberAssignment.Member.Name));
                        }
                        memberAssignmentAnalysis.CheckCompatibleAssignments(mie.Type, ref previous);
                        bool flag = CommonUtil.IsClientType(memberType);
                        if (CommonUtil.IsClientType(memberExpression.Type) && !flag)
                        {
                            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", memberType, memberAssignment.Expression));
                        }
                    }
                }
            }