internal virtual Expression VisitInputReferenceExpression(InputReferenceExpression ire) { Debug.Assert(ire != null, "ire != null -- otherwise caller never should have visited here"); ResourceExpression re = (ResourceExpression)this.Visit(ire.Target); return(re.CreateReference()); }
internal InputReferenceExpression CreateReference() { if (this.inputRef == null) { this.inputRef = new InputReferenceExpression(this); } return(this.inputRef); }
internal InputReferenceExpression CreateReference() { if (this.inputRef == null) { this.inputRef = new InputReferenceExpression(this); } return this.inputRef; }
internal void OverrideInputReference(ResourceSetExpression newInput) { InputReferenceExpression inputRef = newInput.inputRef; if (inputRef != null) { base.inputRef = inputRef; inputRef.OverrideTarget(this); } }
internal override Expression VisitInputReferenceExpression(InputReferenceExpression ire) { Debug.Assert(ire != null, "ire != null"); if (this.parent == null || this.parent.NodeType != ExpressionType.MemberAccess) { string expressionText = (this.parent != null) ? this.parent.ToString() : ire.ToString(); throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(expressionText)); } return(ire); }
internal override Expression VisitInputReferenceExpression(InputReferenceExpression ire) { if ((this.parent == null) || ((!this.InSubScope && (this.parent.NodeType != ExpressionType.MemberAccess)) && (this.parent.NodeType != ExpressionType.TypeAs))) { string str = (this.parent != null) ? this.parent.ToString() : ire.ToString(); throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_CantTranslateExpression(str)); } if (this.InSubScope) { this.builder.Append("$it"); } return(ire); }
/// <summary> /// Instructs this resource set expression to use the input reference expression from <paramref name="newInput"/> as it's /// own input reference, and to retarget the input reference from <paramref name="newInput"/> to this resource set expression. /// </summary> /// <param name="newInput">The resource set expression from which to take the input reference.</param> /// <remarks>Used exclusively by <see cref="ResourceBinder.RemoveTransparentScope"/>.</remarks> internal void OverrideInputReference(ResourceSetExpression newInput) { Debug.Assert(newInput != null, "Original resource set cannot be null"); Debug.Assert(this.inputRef == null, "OverrideInputReference cannot be called if the target has already been referenced"); InputReferenceExpression inputRef = newInput.inputRef; if (inputRef != null) { this.inputRef = inputRef; inputRef.OverrideTarget(this); } }
/// <summary> /// Input resource set references are intentionally omitted from the URL string. /// </summary> /// <param name="ire">The input reference</param> /// <returns>The same input reference expression</returns> internal override Expression VisitInputReferenceExpression(InputReferenceExpression ire) { // This method intentionally does not write anything to the URI. // This is how 'Where(<input>.Id == 5)' becomes '$filter=Id eq 5'. Debug.Assert(ire != null, "ire != null"); if (this.parent == null || this.parent.NodeType != ExpressionType.MemberAccess) { // Ideally we refer to the parent expression as the un-translatable one, // because we cannot reference 'this' as a standalone expression; however // if the parent is null for any reasonn, we fall back to the expression itself. string expressionText = (this.parent != null) ? this.parent.ToString() : ire.ToString(); throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(expressionText)); } return(ire); }
/// <summary> /// Input resource set references are intentionally omitted from the URL string for the top level /// refences to input parameter (i.e. outside of any/all methods). /// For parameter references to input (range variable for Where) inside any/all methods we write "$it". /// </summary> /// <param name="ire">The input reference</param> /// <returns>The same input reference expression</returns> internal override Expression VisitInputReferenceExpression(InputReferenceExpression ire) { // This method intentionally does not write anything to the URI for implicit references to the input parameter ($it). // This is how 'Where(<input>.Id == 5)' becomes '$filter=Id eq 5'. Debug.Assert(ire != null, "ire != null"); if (this.parent == null || (!this.InSubScope && this.parent.NodeType != ExpressionType.MemberAccess && this.parent.NodeType != ExpressionType.TypeAs)) { // Ideally we refer to the parent expression as the un-translatable one, // because we cannot reference 'this' as a standalone expression; however // if the parent is null for any reasonn, we fall back to the expression itself. string expressionText = (this.parent != null) ? this.parent.ToString() : ire.ToString(); throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(expressionText)); } // Write "$it" for input parameter reference inside any/all methods if (this.InSubScope) { this.builder.Append(XmlConstants.ImplicitFilterParameter); } return(ire); }
/// <summary> /// Visit an <see cref="InputReferenceExpression"/>, producing a new InputReferenceExpression /// based on the visited form of the <see cref="ResourceSetExpression"/> that is referenced by /// the InputReferenceExpression argument, <paramref name="ire"/>. /// </summary> /// <param name="ire">InputReferenceExpression expression to visit</param> /// <returns>Visited InputReferenceExpression expression</returns> internal virtual Expression VisitInputReferenceExpression(InputReferenceExpression ire) { Debug.Assert(ire != null, "ire != null -- otherwise caller never should have visited here"); ResourceExpression re = (ResourceExpression)this.Visit(ire.Target); return re.CreateReference(); }
/// <summary> /// Resolves member accesses that represent transparent scope property accesses to the corresponding resource set, /// iff the input resource set is enclosed in a transparent scope and the specified MemberExpression represents /// such a property access. /// </summary> /// <param name="m">MemberExpression expression to visit</param> /// <returns> /// An InputReferenceExpression if the member access represents a transparent scope property /// access that can be resolved to a resource set in the path that produces the input resource set; /// otherwise the same MemberExpression is returned. /// </returns> internal override Expression VisitMemberAccess(MemberExpression m) { // If the current input resource set is not enclosed in a transparent scope, then this // MemberExpression cannot represent a valid transparent scope access based on the input parameter. if (this.inputSet == null || !this.inputSet.HasTransparentScope) { return(base.VisitMemberAccess(m)); } ParameterExpression innerParamRef = null; Stack <PropertyInfo> nestedAccesses = new Stack <PropertyInfo>(); MemberExpression memberRef = m; while (memberRef != null && PlatformHelper.IsProperty(memberRef.Member) && memberRef.Expression != null) { nestedAccesses.Push((PropertyInfo)memberRef.Member); if (memberRef.Expression.NodeType == ExpressionType.Parameter) { innerParamRef = (ParameterExpression)memberRef.Expression; } memberRef = memberRef.Expression as MemberExpression; } // Only continue if the inner non-MemberExpression is the input reference ParameterExpression and // at least one property reference is present - otherwise this cannot be a transparent scope access. if (innerParamRef != this.inputParameter || nestedAccesses.Count == 0) { return(m); } ResourceExpression target = this.input; ResourceSetExpression targetSet = this.inputSet; bool transparentScopeTraversed = false; // Process all the traversals through transparent scopes. while (nestedAccesses.Count > 0) { if (targetSet == null || !targetSet.HasTransparentScope) { break; } // Peek the property; pop it once it's consumed // (it could be a non-transparent-identifier access). PropertyInfo currentProp = nestedAccesses.Peek(); // If this is the accessor for the target, then the member // refers to the target itself. if (currentProp.Name.Equals(targetSet.TransparentScope.Accessor, StringComparison.Ordinal)) { target = targetSet; nestedAccesses.Pop(); transparentScopeTraversed = true; continue; } // This member could also be one of the in-scope sources of the target. Expression source; if (!targetSet.TransparentScope.SourceAccessors.TryGetValue(currentProp.Name, out source)) { break; } transparentScopeTraversed = true; nestedAccesses.Pop(); Debug.Assert(source != null, "source != null -- otherwise ResourceBinder created an accessor to nowhere"); InputReferenceExpression sourceReference = source as InputReferenceExpression; if (sourceReference == null) { targetSet = source as ResourceSetExpression; if (targetSet == null || !targetSet.HasTransparentScope) { target = (ResourceExpression)source; } } else { targetSet = sourceReference.Target as ResourceSetExpression; target = targetSet; } } // If no traversals were made, the original expression is OK. if (!transparentScopeTraversed) { return(m); } // Process traversals after the transparent scope. Expression result = this.CreateReference(target); while (nestedAccesses.Count > 0) { result = Expression.Property(result, nestedAccesses.Pop()); } return(result); }
internal override Expression VisitMemberAccess(MemberExpression m) { if ((this.inputSet == null) || !this.inputSet.HasTransparentScope) { return(base.VisitMemberAccess(m)); } ParameterExpression expression = null; Stack <PropertyInfo> stack = new Stack <PropertyInfo>(); for (MemberExpression expression2 = m; ((expression2 != null) && PlatformHelper.IsProperty(expression2.Member)) && (expression2.Expression != null); expression2 = expression2.Expression as MemberExpression) { stack.Push((PropertyInfo)expression2.Member); if (expression2.Expression.NodeType == ExpressionType.Parameter) { expression = (ParameterExpression)expression2.Expression; } } if ((expression != this.inputParameter) || (stack.Count == 0)) { return(m); } ResourceExpression input = this.input; ResourceSetExpression inputSet = this.inputSet; bool flag = false; while (stack.Count > 0) { if ((inputSet == null) || !inputSet.HasTransparentScope) { break; } PropertyInfo info = stack.Peek(); if (info.Name.Equals(inputSet.TransparentScope.Accessor, StringComparison.Ordinal)) { input = inputSet; stack.Pop(); flag = true; } else { Expression expression5; if (!inputSet.TransparentScope.SourceAccessors.TryGetValue(info.Name, out expression5)) { break; } flag = true; stack.Pop(); InputReferenceExpression expression6 = expression5 as InputReferenceExpression; if (expression6 == null) { inputSet = expression5 as ResourceSetExpression; if ((inputSet == null) || !inputSet.HasTransparentScope) { input = (ResourceExpression)expression5; } continue; } inputSet = expression6.Target as ResourceSetExpression; input = inputSet; } } if (!flag) { return(m); } Expression expression7 = this.CreateReference(input); while (stack.Count > 0) { expression7 = Expression.Property(expression7, stack.Pop()); } return(expression7); }
internal virtual Expression VisitInputReferenceExpression(InputReferenceExpression ire) { ResourceExpression expression = (ResourceExpression)this.Visit(ire.Target); return(expression.CreateReference()); }
internal virtual Expression VisitInputReferenceExpression(InputReferenceExpression ire) { ResourceExpression expression = (ResourceExpression) this.Visit(ire.Target); return expression.CreateReference(); }
/// <summary> /// Input resource set references are intentionally omitted from the URL string. /// </summary> /// <param name="ire">The input reference</param> /// <returns>The same input reference expression</returns> internal override Expression VisitInputReferenceExpression(InputReferenceExpression ire) { // This method intentionally does not write anything to the URI. // This is how 'Where(<input>.Id == 5)' becomes '$filter=Id eq 5'. Debug.Assert(ire != null, "ire != null"); if (this.parent == null || this.parent.NodeType != ExpressionType.MemberAccess) { // Ideally we refer to the parent expression as the un-translatable one, // because we cannot reference 'this' as a standalone expression; however // if the parent is null for any reasonn, we fall back to the expression itself. string expressionText = (this.parent != null) ? this.parent.ToString() : ire.ToString(); throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(expressionText)); } return ire; }
internal override Expression VisitInputReferenceExpression(InputReferenceExpression ire) { Debug.Assert(ire != null, "ire != null"); if (this.parent == null || this.parent.NodeType != ExpressionType.MemberAccess) { string expressionText = (this.parent != null) ? this.parent.ToString() : ire.ToString(); throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(expressionText)); } return ire; }
internal override Expression VisitMemberAccess(MemberExpression m) { if (this.inputSet == null || !this.inputSet.HasTransparentScope) { return(base.VisitMemberAccess(m)); } ParameterExpression innerParamRef = null; Stack <PropertyInfo> nestedAccesses = new Stack <PropertyInfo>(); MemberExpression memberRef = m; while (memberRef != null && memberRef.Member.MemberType == MemberTypes.Property && memberRef.Expression != null) { nestedAccesses.Push((PropertyInfo)memberRef.Member); if (memberRef.Expression.NodeType == ExpressionType.Parameter) { innerParamRef = (ParameterExpression)memberRef.Expression; } memberRef = memberRef.Expression as MemberExpression; } if (innerParamRef != this.inputParameter || nestedAccesses.Count == 0) { return(m); } ResourceExpression target = this.input; ResourceSetExpression targetSet = this.inputSet; bool transparentScopeTraversed = false; while (nestedAccesses.Count > 0) { if (targetSet == null || !targetSet.HasTransparentScope) { break; } PropertyInfo currentProp = nestedAccesses.Peek(); if (currentProp.Name.Equals(targetSet.TransparentScope.Accessor, StringComparison.Ordinal)) { target = targetSet; nestedAccesses.Pop(); transparentScopeTraversed = true; continue; } Expression source; if (!targetSet.TransparentScope.SourceAccessors.TryGetValue(currentProp.Name, out source)) { break; } transparentScopeTraversed = true; nestedAccesses.Pop(); Debug.Assert(source != null, "source != null -- otherwise ResourceBinder created an accessor to nowhere"); InputReferenceExpression sourceReference = source as InputReferenceExpression; if (sourceReference == null) { targetSet = source as ResourceSetExpression; if (targetSet == null || !targetSet.HasTransparentScope) { target = (ResourceExpression)source; } } else { targetSet = sourceReference.Target as ResourceSetExpression; target = targetSet; } } if (!transparentScopeTraversed) { return(m); } Expression result = this.CreateReference(target); while (nestedAccesses.Count > 0) { result = Expression.Property(result, nestedAccesses.Pop()); } return(result); }
internal override Expression VisitInputReferenceExpression(InputReferenceExpression ire) { if ((this.parent == null) || ((!this.InSubScope && (this.parent.NodeType != ExpressionType.MemberAccess)) && (this.parent.NodeType != ExpressionType.TypeAs))) { string str = (this.parent != null) ? this.parent.ToString() : ire.ToString(); throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_CantTranslateExpression(str)); } if (this.InSubScope) { this.builder.Append("$it"); } return ire; }