Exemple #1
0
 internal static bool Analyze(LambdaExpression le, ResourceExpression re, bool matchMembers)
 {
     if (le.Body.NodeType == ExpressionType.Constant)
     {
         if (CommonUtil.IsClientType(le.Body.Type))
         {
             throw new NotSupportedException("Referencing of local entity type instances not supported when projecting results.");
         }
         re.Projection = new ProjectionQueryOptionExpression(le.Body.Type, le, new List <string>());
         return(true);
     }
     if (le.Body.NodeType == ExpressionType.Call)
     {
         MethodCallExpression methodCallExpression = le.Body as MethodCallExpression;
         if (methodCallExpression.Method == ReflectionUtil.ProjectMethodInfo.MakeGenericMethod(le.Body.Type))
         {
             ConstantExpression constantExpression = methodCallExpression.Arguments[1] as ConstantExpression;
             re.Projection = new ProjectionQueryOptionExpression(le.Body.Type, ProjectionQueryOptionExpression.DefaultLambda, new List <string>((string[])constantExpression.Value));
             return(true);
         }
     }
     if (le.Body.NodeType == ExpressionType.MemberInit || le.Body.NodeType == ExpressionType.New)
     {
         AnalyzeResourceExpression(le, re);
         return(true);
     }
     if (matchMembers && SkipConverts(le.Body).NodeType == ExpressionType.MemberAccess)
     {
         AnalyzeResourceExpression(le, re);
         return(true);
     }
     return(false);
 }
Exemple #2
0
        internal static void Analyze(LambdaExpression e, PathBox pb)
        {
            bool num = CommonUtil.IsClientType(e.Body.Type);

            pb.PushParamExpression(e.Parameters.Last());
            if (!num)
            {
                NonEntityProjectionAnalyzer.Analyze(e.Body, pb);
            }
            else
            {
                switch (e.Body.NodeType)
                {
                case ExpressionType.MemberInit:
                    EntityProjectionAnalyzer.Analyze((MemberInitExpression)e.Body, pb);
                    break;

                case ExpressionType.New:
                    throw new NotSupportedException("Construction of entity type instances must use object initializer with default constructor.");

                case ExpressionType.Constant:
                    throw new NotSupportedException("Referencing of local entity type instances not supported when projecting results.");

                default:
                    NonEntityProjectionAnalyzer.Analyze(e.Body, pb);
                    break;
                }
            }
            pb.PopParamExpression();
        }
        internal void AppendToPath(PropertyInfo pi)
        {
            Type          elementType = TypeSystem.GetElementType(pi.PropertyType);
            StringBuilder stringBuilder;

            if (CommonUtil.IsClientType(elementType))
            {
                stringBuilder = expandPaths.Last();
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append('/');
                }
                stringBuilder.Append(pi.Name);
            }
            stringBuilder = projectionPaths.Last();
            RemoveEntireEntityMarkerIfPresent(stringBuilder);
            if (stringBuilder.Length > 0)
            {
                stringBuilder.Append('/');
            }
            stringBuilder.Append(pi.Name);
            if (CommonUtil.IsClientType(elementType))
            {
                AddEntireEntityMarker(stringBuilder);
            }
        }
Exemple #4
0
 internal override Expression VisitConstant(ConstantExpression c)
 {
     if (CommonUtil.IsClientType(c.Type))
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, c.ToString()));
     }
     return(base.VisitConstant(c));
 }
Exemple #5
0
 internal override Expression VisitInvocation(InvocationExpression iv)
 {
     if (CommonUtil.IsClientType(iv.Expression.Type) || iv.Arguments.Any((Expression a) => CommonUtil.IsClientType(a.Type)))
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, iv.ToString()));
     }
     return(base.VisitInvocation(iv));
 }
Exemple #6
0
 internal override Expression VisitBinary(BinaryExpression b)
 {
     if (CommonUtil.IsClientType(b.Left.Type) || CommonUtil.IsClientType(b.Right.Type))
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, b.ToString()));
     }
     return(base.VisitBinary(b));
 }
Exemple #7
0
 internal override Expression VisitUnary(UnaryExpression u)
 {
     if (!ResourceBinder.PatternRules.MatchConvertToAssignable(u) && CommonUtil.IsClientType(u.Operand.Type))
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, u.ToString()));
     }
     return(base.VisitUnary(u));
 }
Exemple #8
0
 private static void Analyze(MemberInitExpression mie, PathBox pb)
 {
     if (CommonUtil.IsClientType(mie.Type))
     {
         EntityProjectionAnalyzer.Analyze(mie, pb);
     }
     else
     {
         NonEntityProjectionAnalyzer.Analyze(mie, pb);
     }
 }
Exemple #9
0
 internal override Expression VisitMethodCall(MethodCallExpression m)
 {
     if (IsMethodCallAllowedEntitySequence(m))
     {
         CheckChainedSequence(m, type);
         return(base.VisitMethodCall(m));
     }
     if ((m.Object != null && CommonUtil.IsClientType(m.Object.Type)) || m.Arguments.Any((Expression a) => CommonUtil.IsClientType(a.Type)))
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, m.ToString()));
     }
     return(base.VisitMethodCall(m));
 }
Exemple #10
0
 internal override Expression VisitConditional(ConditionalExpression c)
 {
     ResourceBinder.PatternRules.MatchNullCheckResult matchNullCheckResult = ResourceBinder.PatternRules.MatchNullCheck(box.ParamExpressionInScope, c);
     if (matchNullCheckResult.Match)
     {
         Visit(matchNullCheckResult.AssignExpression);
         return(c);
     }
     if (CommonUtil.IsClientType(c.Test.Type) || CommonUtil.IsClientType(c.IfTrue.Type) || CommonUtil.IsClientType(c.IfFalse.Type))
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, c.ToString()));
     }
     return(base.VisitConditional(c));
 }
Exemple #11
0
            internal override Expression VisitMemberAccess(MemberExpression m)
            {
                if (!CommonUtil.IsClientType(m.Expression.Type))
                {
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", type, m.ToString()));
                }
                PropertyInfo propInfo = null;

                if (ResourceBinder.PatternRules.MatchNonPrivateReadableProperty(m, out propInfo))
                {
                    Expression result = base.VisitMemberAccess(m);
                    box.AppendToPath(propInfo);
                    return(result);
                }
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", type, m.ToString()));
            }
Exemple #12
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));
                        }
                    }
                }
            }