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
        private static void AnalyzeResourceExpression(LambdaExpression lambda, ResourceExpression resource)
        {
            PathBox pathBox = new PathBox();

            Analyze(lambda, pathBox);
            resource.Projection  = new ProjectionQueryOptionExpression(lambda.Body.Type, lambda, pathBox.ProjectionPaths.ToList());
            resource.ExpandPaths = pathBox.ExpandPaths.Union(resource.ExpandPaths, StringComparer.Ordinal).ToList();
        }
        internal static Expression Bind(Expression e, ResourceExpression currentInput, ParameterExpression inputParameter, List <ResourceExpression> referencedInputs)
        {
            InputBinder inputBinder = new InputBinder(currentInput, inputParameter);
            Expression  result      = inputBinder.Visit(e);

            referencedInputs.AddRange(inputBinder.referencedInputs);
            return(result);
        }
Exemple #4
0
        internal void VisitQueryOptions(ResourceExpression re)
        {
            if (!re.HasQueryOptions)
            {
                return;
            }
            ResourceSetExpression resourceSetExpression = re as ResourceSetExpression;

            if (resourceSetExpression != null)
            {
                IEnumerator enumerator = resourceSetExpression.SequenceQueryOptions.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Expression expression = (Expression)enumerator.Current;
                    switch (expression.NodeType)
                    {
                    case (ExpressionType)10009:
                        VisitQueryOptionExpression((RequestOptionsQueryOptionExpression)expression);
                        break;

                    case (ExpressionType)10010:
                        VisitQueryOptionExpression((OperationContextQueryOptionExpression)expression);
                        break;

                    case (ExpressionType)10011:
                        VisitQueryOptionExpression((EntityResolverQueryOptionExpression)expression);
                        break;

                    case (ExpressionType)10003:
                        VisitQueryOptionExpression((TakeQueryOptionExpression)expression);
                        break;

                    case (ExpressionType)10006:
                        VisitQueryOptionExpression((FilterQueryOptionExpression)expression);
                        break;
                    }
                }
            }
            if (re.Projection != null && re.Projection.Paths.Count > 0)
            {
                Projection    = re.Projection;
                SelectColumns = re.Projection.Paths;
            }
            if (re.CustomQueryOptions.Count > 0)
            {
                VisitCustomQueryOptions(re.CustomQueryOptions);
            }
        }
        #pragma warning restore 612, 618

        internal void OverrideTarget(ResourceSetExpression newTarget)
        {
            target = newTarget;
        }
 #pragma warning disable 612, 618
 internal InputReferenceExpression(ResourceExpression target)
     : base((ExpressionType)10007, target.ResourceType)
 {
     this.target = target;
 }
        internal override Expression VisitMemberAccess(MemberExpression m)
        {
            if (inputSet == null || !inputSet.HasTransparentScope)
            {
                return(base.VisitMemberAccess(m));
            }
            ParameterExpression  parameterExpression = null;
            Stack <PropertyInfo> stack            = new Stack <PropertyInfo>();
            MemberExpression     memberExpression = m;

            while (memberExpression != null && memberExpression.Member.MemberType == MemberTypes.Property && memberExpression.Expression != null)
            {
                stack.Push((PropertyInfo)memberExpression.Member);
                if (memberExpression.Expression.NodeType == ExpressionType.Parameter)
                {
                    parameterExpression = (ParameterExpression)memberExpression.Expression;
                }
                memberExpression = (memberExpression.Expression as MemberExpression);
            }
            if (parameterExpression != inputParameter || stack.Count == 0)
            {
                return(m);
            }
            ResourceExpression    resource = input;
            ResourceSetExpression resourceSetExpression = inputSet;
            bool flag = false;

            while (stack.Count > 0 && resourceSetExpression != null && resourceSetExpression.HasTransparentScope)
            {
                PropertyInfo propertyInfo = stack.Peek();
                if (propertyInfo.Name.Equals(resourceSetExpression.TransparentScope.Accessor, StringComparison.Ordinal))
                {
                    resource = resourceSetExpression;
                    stack.Pop();
                    flag = true;
                    continue;
                }
                if (!resourceSetExpression.TransparentScope.SourceAccessors.TryGetValue(propertyInfo.Name, out Expression value))
                {
                    break;
                }
                flag = true;
                stack.Pop();
                InputReferenceExpression inputReferenceExpression = value as InputReferenceExpression;
                if (inputReferenceExpression == null)
                {
                    resourceSetExpression = (value as ResourceSetExpression);
                    if (resourceSetExpression == null || !resourceSetExpression.HasTransparentScope)
                    {
                        resource = (ResourceExpression)value;
                    }
                }
                else
                {
                    resourceSetExpression = (inputReferenceExpression.Target as ResourceSetExpression);
                    resource = resourceSetExpression;
                }
            }
            if (!flag)
            {
                return(m);
            }
            Expression expression = CreateReference(resource);

            while (stack.Count > 0)
            {
                expression = Expression.Property(expression, stack.Pop());
            }
            return(expression);
        }
 private InputBinder(ResourceExpression resource, ParameterExpression setReferenceParam)
 {
     input          = resource;
     inputSet       = (resource as ResourceSetExpression);
     inputParameter = setReferenceParam;
 }
 private Expression CreateReference(ResourceExpression resource)
 {
     referencedInputs.Add(resource);
     return(resource.CreateReference());
 }