Beispiel #1
0
        public void BindApplyWithAggregateAndFilterShouldReturnApplyClause()
        {
            IEnumerable <QueryToken> tokens        = _parser.ParseApply("aggregate(StockQuantity with sum as TotalPrice)/filter(TotalPrice eq 100)");
            MetadataBinder           metadataBiner = new MetadataBinder(_bindingState);
            ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState);
            ApplyClause actual = binder.BindApply(tokens);

            Assert.NotNull(actual);
            Assert.Equal(2, actual.Transformations.Count());

            List <TransformationNode> transformations = actual.Transformations.ToList();

            Assert.NotNull(transformations[1]);
            FilterTransformationNode filter = Assert.IsType <FilterTransformationNode>(transformations[1]);

            Assert.Equal(TransformationNodeKind.Filter, filter.Kind);

            FilterClause filterClause = filter.FilterClause;

            Assert.NotNull(filterClause.Expression);
            BinaryOperatorNode binaryOperation = Assert.IsType <BinaryOperatorNode>(filterClause.Expression);

            Assert.NotNull(binaryOperation.Left);
            ConvertNode propertyConvertNode = Assert.IsType <ConvertNode>(binaryOperation.Left);

            Assert.NotNull(propertyConvertNode.Source);
            SingleValueOpenPropertyAccessNode propertyAccess = Assert.IsType <SingleValueOpenPropertyAccessNode>(propertyConvertNode.Source);

            Assert.Equal("TotalPrice", propertyAccess.Name);
        }
Beispiel #2
0
        public void BindApplyWithAggregateAndFilterShouldReturnApplyClause()
        {
            IEnumerable <QueryToken> tokens        = _parser.ParseApply("aggregate(StockQuantity with sum as TotalPrice)/filter(TotalPrice eq 100)");
            MetadataBinder           metadataBiner = new MetadataBinder(_bindingState);
            ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState);
            ApplyClause actual = binder.BindApply(tokens);

            actual.Should().NotBeNull();
            actual.Transformations.Should().HaveCount(2);

            List <TransformationNode> transformations = actual.Transformations.ToList();
            FilterTransformationNode  filter          = transformations[1] as FilterTransformationNode;

            filter.Should().NotBeNull();
            filter.Kind.Should().Be(TransformationNodeKind.Filter);

            FilterClause filterClause = filter.FilterClause;

            filterClause.Expression.Should().NotBeNull();
            BinaryOperatorNode binaryOperation = filterClause.Expression as BinaryOperatorNode;

            binaryOperation.Should().NotBeNull();
            ConvertNode propertyConvertNode = binaryOperation.Left as ConvertNode;

            propertyConvertNode.Should().NotBeNull();
            SingleValueOpenPropertyAccessNode propertyAccess = propertyConvertNode.Source as SingleValueOpenPropertyAccessNode;

            propertyAccess.Should().NotBeNull();
            propertyAccess.Name.Should().Be("TotalPrice");
        }
Beispiel #3
0
        private void TestOpenProperty <TParam, TReturn>(SingleValueNode source, string propertyName, Expression <Func <TParam, TReturn> > expectedExpression)
        {
            QueryNode node   = new SingleValueOpenPropertyAccessNode(source, propertyName);
            var       result = this.testSubject.TranslateNode(node);

            CompareExpressions(expectedExpression.Body, result);
        }
        /// <summary>
        /// Bind $it to the <see cref="QueryNode"/> translated string.
        /// </summary>
        /// <param name="node">node to bind.</param>
        /// <param name="filterClauseRangeVariable">The <see cref="FilterClause"/> range variable.</param>
        /// <returns>The translated string with $it binding.</returns>
        private string BindNode(QueryNode node, ResourceRangeVariable filterClauseRangeVariable)
        {
            BinaryOperatorNode                binaryNode = node as BinaryOperatorNode;
            InNode                            inNode     = node as InNode;
            AnyNode                           anyNode    = node as AnyNode;
            SingleValueFunctionCallNode       singleValueFunctionCallNode       = node as SingleValueFunctionCallNode;
            SingleValueOpenPropertyAccessNode singleValueOpenPropertyAccessNode = node as SingleValueOpenPropertyAccessNode;

            if (binaryNode != null)
            {
                return(BindBinaryOperatorNode(binaryNode, filterClauseRangeVariable));
            }
            else if (inNode != null)
            {
                return(BindInNode(inNode, filterClauseRangeVariable));
            }
            else if (anyNode != null)
            {
                return(BindAnyNode(anyNode, filterClauseRangeVariable));
            }
            else if (singleValueFunctionCallNode != null)
            {
                return(BindSingleValueFunctionCallNode(singleValueFunctionCallNode, filterClauseRangeVariable));
            }
            else if (singleValueOpenPropertyAccessNode != null)
            {
                return(BindSingleValueOpenPropertyAccess(singleValueOpenPropertyAccessNode, filterClauseRangeVariable));
            }
            else
            {
                return(this.TranslateNode(node));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Binds a <see cref="SingleValueOpenPropertyAccessNode"/> to create a LINQ <see cref="Expression"/> that
        /// represents the semantics of the <see cref="SingleValueOpenPropertyAccessNode"/>.
        /// </summary>
        /// <param name="openNode">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public virtual Expression BindDynamicPropertyAccessQueryNode(SingleValueOpenPropertyAccessNode openNode)
        {
            if (EdmLibHelpers.IsDynamicTypeWrapper(_filterType))
            {
                return(GetFlattenedPropertyExpression(openNode.Name) ?? Expression.Property(Bind(openNode.Source), openNode.Name));
            }
            PropertyInfo prop = GetDynamicPropertyContainer(openNode);

            var propertyAccessExpression        = BindPropertyAccessExpression(openNode, prop);
            var readDictionaryIndexerExpression = Expression.Property(propertyAccessExpression,
                                                                      DictionaryStringObjectIndexerName, Expression.Constant(openNode.Name));
            var containsKeyExpression = Expression.Call(propertyAccessExpression,
                                                        propertyAccessExpression.Type.GetMethod("ContainsKey"), Expression.Constant(openNode.Name));
            var nullExpression = Expression.Constant(null);

            if (QuerySettings.HandleNullPropagation == HandleNullPropagationOption.True)
            {
                var dynamicDictIsNotNull = Expression.NotEqual(propertyAccessExpression, Expression.Constant(null));
                var dynamicDictIsNotNullAndContainsKey = Expression.AndAlso(dynamicDictIsNotNull, containsKeyExpression);
                return(Expression.Condition(
                           dynamicDictIsNotNullAndContainsKey,
                           readDictionaryIndexerExpression,
                           nullExpression));
            }
            else
            {
                return(Expression.Condition(
                           containsKeyExpression,
                           readDictionaryIndexerExpression,
                           nullExpression));
            }
        }
Beispiel #6
0
        public override Expression BindDynamicPropertyAccessQueryNode(SingleValueOpenPropertyAccessNode openNode)
        {
            string fieldPath = openNode.Name;

            if (!fieldPath.StartsWith("$."))
            {
                fieldPath = $"$.{fieldPath}";
            }

            fieldPath = fieldPath.Replace("__", ".");

            //add JSON_VALUE support to open types
            PropertyInfo prop = GetDynamicPropertyContainer(openNode);
            //get parameter expression
            var source      = Bind(openNode.Source);
            var propertyExp = Expression.Property(source, prop);
            //call JSON_VALUE function on this open property with user selected key
            var jsonEXP = Expression.Call(
                typeof(DbJsonValueExtensions).GetMethod(
                    nameof(DbJsonValueExtensions.JSON_VALUE),
                    new Type[] { typeof(string), typeof(string) }),
                Expression.Convert(propertyExp, typeof(string)),
                Expression.Constant(fieldPath));

            return(jsonEXP);
        }
Beispiel #7
0
        /// <summary>
        /// We return the <see cref="ResourceRangeVariableReferenceNode"/> within a <see cref="QueryNode"/>
        /// </summary>
        /// <param name="node">The node to extract the ResourceRangeVariableReferenceNode.</param>
        /// <returns>The extracted ResourceRangeVariableReferenceNode.</returns>
        private ResourceRangeVariableReferenceNode GetResourceRangeVariableReferenceNode(QueryNode node)
        {
            if (node == null)
            {
                return(null);
            }

            switch (node.Kind)
            {
            case QueryNodeKind.SingleValuePropertyAccess:
                SingleValuePropertyAccessNode singleValuePropertyAccessNode = node as SingleValuePropertyAccessNode;
                return(GetResourceRangeVariableReferenceNode(singleValuePropertyAccessNode.Source));

            case QueryNodeKind.Convert:
                ConvertNode convertNode = node as ConvertNode;
                return(GetResourceRangeVariableReferenceNode(convertNode.Source));

            case QueryNodeKind.Any:
                AnyNode anyNode = node as AnyNode;
                return(GetResourceRangeVariableReferenceNode(anyNode.Source));

            case QueryNodeKind.SingleValueFunctionCall:
                SingleValueFunctionCallNode singleValueFunctionCallNode = node as SingleValueFunctionCallNode;
                return(GetResourceRangeVariableReferenceNode(singleValueFunctionCallNode.Parameters.First()));

            case QueryNodeKind.ResourceRangeVariableReference:
                return(node as ResourceRangeVariableReferenceNode);

            case QueryNodeKind.SingleValueOpenPropertyAccess:
                SingleValueOpenPropertyAccessNode singleValueOpenPropertyAccessNode = node as SingleValueOpenPropertyAccessNode;
                return(GetResourceRangeVariableReferenceNode(singleValueOpenPropertyAccessNode.Source));

            case QueryNodeKind.SingleComplexNode:
                SingleComplexNode singleComplexNode = node as SingleComplexNode;
                return(GetResourceRangeVariableReferenceNode(singleComplexNode.Source));

            case QueryNodeKind.CollectionComplexNode:
                CollectionComplexNode collectionComplexNode = node as CollectionComplexNode;
                return(GetResourceRangeVariableReferenceNode(collectionComplexNode.Source));

            case QueryNodeKind.CollectionNavigationNode:
                CollectionNavigationNode collectionNavigationNode = node as CollectionNavigationNode;
                return(GetResourceRangeVariableReferenceNode(collectionNavigationNode.Source));

            case QueryNodeKind.SingleNavigationNode:
                SingleNavigationNode singleNavigationNode = node as SingleNavigationNode;
                return(GetResourceRangeVariableReferenceNode(singleNavigationNode.Source));

            case QueryNodeKind.CollectionResourceFunctionCall:
                CollectionResourceFunctionCallNode collectionResourceFunctionCallNode = node as CollectionResourceFunctionCallNode;
                return(GetResourceRangeVariableReferenceNode(collectionResourceFunctionCallNode.Source));

            case QueryNodeKind.SingleResourceFunctionCall:
                SingleResourceFunctionCallNode singleResourceFunctionCallNode = node as SingleResourceFunctionCallNode;
                return(GetResourceRangeVariableReferenceNode(singleResourceFunctionCallNode.Source));
            }

            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Translate a SingleValueOpenPropertyAccessNode.
        /// </summary>
        /// <param name="nodeIn">The node to be translated.</param>
        /// <returns>The translated node.</returns>
        public override QueryNode Visit(SingleValueOpenPropertyAccessNode nodeIn)
        {
            Contract.Assert(nodeIn != null);

            return(new SingleValueOpenPropertyAccessNode(
                       (SingleValueNode)nodeIn.Source.Accept(this),
                       nodeIn.Name));
        }
Beispiel #9
0
        private GroupByTransformationNode BindGroupByToken(GroupByToken token)
        {
            List <GroupByPropertyNode> properties = new List <GroupByPropertyNode>();

            foreach (EndPathToken propertyToken in token.Properties)
            {
                QueryNode bindResult = this.bindMethod(propertyToken);
                SingleValuePropertyAccessNode property        = bindResult as SingleValuePropertyAccessNode;
                SingleComplexNode             complexProperty = bindResult as SingleComplexNode;

                if (property != null)
                {
                    RegisterProperty(properties, ReversePropertyPath(property));
                }
                else if (complexProperty != null)
                {
                    RegisterProperty(properties, ReversePropertyPath(complexProperty));
                }
                else
                {
                    SingleValueOpenPropertyAccessNode openProperty = bindResult as SingleValueOpenPropertyAccessNode;
                    if (openProperty != null)
                    {
                        IEdmTypeReference type = GetTypeReferenceByPropertyName(openProperty.Name);
                        properties.Add(new GroupByPropertyNode(openProperty.Name, openProperty, type));
                    }
                    else
                    {
                        throw new ODataException(
                                  ODataErrorStrings.ApplyBinder_GroupByPropertyNotPropertyAccessValue(propertyToken.Identifier));
                    }
                }
            }

            var newProperties = new HashSet <EndPathToken>(((GroupByToken)token).Properties);

            TransformationNode aggregate = null;

            if (token.Child != null)
            {
                if (token.Child.Kind == QueryTokenKind.Aggregate)
                {
                    aggregate = BindAggregateToken((AggregateToken)token.Child);
                    aggregateExpressionsCache = ((AggregateTransformationNode)aggregate).AggregateExpressions;
                    newProperties.UnionWith(aggregateExpressionsCache.Select(statement => new EndPathToken(statement.Alias, null)));
                }
                else
                {
                    throw new ODataException(ODataErrorStrings.ApplyBinder_UnsupportedGroupByChild(token.Child.Kind));
                }
            }

            state.AggregatedPropertyNames = newProperties;

            // TODO: Determine source
            return(new GroupByTransformationNode(properties, aggregate, null));
        }
Beispiel #10
0
        private IEdmTypeReference CreateAggregateExpressionTypeReference(SingleValueNode expression, AggregationMethodDefinition method)
        {
            IEdmTypeReference expressionType = expression.TypeReference;

            if (expressionType == null && aggregateExpressionsCache != null)
            {
                SingleValueOpenPropertyAccessNode openProperty = expression as SingleValueOpenPropertyAccessNode;
                if (openProperty != null)
                {
                    expressionType = GetTypeReferenceByPropertyName(openProperty.Name);
                }
            }

            switch (method.MethodKind)
            {
            case AggregationMethod.Average:
                EdmPrimitiveTypeKind expressionPrimitiveKind = expressionType.PrimitiveKind();
                switch (expressionPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Int32:
                case EdmPrimitiveTypeKind.Int64:
                case EdmPrimitiveTypeKind.Double:
                    return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, expressionType.IsNullable));

                case EdmPrimitiveTypeKind.Decimal:
                    return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Decimal, expressionType.IsNullable));

                case EdmPrimitiveTypeKind.Single:
                    return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Single, expressionType.IsNullable));

                case EdmPrimitiveTypeKind.None:
                    return(expressionType);

                default:
                    throw new ODataException(
                              ODataErrorStrings.ApplyBinder_AggregateExpressionIncompatibleTypeForMethod(expression,
                                                                                                         expressionPrimitiveKind));
                }

            case AggregationMethod.VirtualPropertyCount:
            case AggregationMethod.CountDistinct:
                // Issue #758: CountDistinct and $Count should return type Edm.Decimal with Scale="0" and sufficient Precision.
                return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int64, false));

            case AggregationMethod.Max:
            case AggregationMethod.Min:
            case AggregationMethod.Sum:
                return(expressionType);

            default:
                // Only the EdmModel knows which type the custom aggregation methods returns.
                // Since we do not have a reference for it, right now we are assuming that all custom aggregation methods returns Doubles
                // TODO: find a appropriate way of getting the return type.
                return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, expressionType.IsNullable));
            }
        }
Beispiel #11
0
        public override QueryNode Visit(SingleValueOpenPropertyAccessNode nodeIn)
        {
            SingleValueNode?source = nodeIn.Source == null ? null : (SingleValueNode)Visit(nodeIn.Source);

            if (nodeIn.Source != source)
            {
                nodeIn = new SingleValueOpenPropertyAccessNode(source, nodeIn.Name);
            }
            return(nodeIn);
        }
        /// <summary>
        /// Translate a SingleValueOpenPropertyAccessNode.
        /// </summary>
        /// <param name="nodeIn">The node to be translated.</param>
        /// <returns>The translated node.</returns>
        public override QueryNode Visit(SingleValueOpenPropertyAccessNode nodeIn)
        {
            if (nodeIn == null)
            {
                throw Error.ArgumentNull(nameof(nodeIn));
            }

            return(new SingleValueOpenPropertyAccessNode(
                       (SingleValueNode)nodeIn.Source.Accept(this),
                       nodeIn.Name));
        }
        public void EqualsOnEntityAndNullIsSupported()
        {
            IEdmTypeReference left      = HardCodedTestModel.GetPersonTypeReference();
            IEdmTypeReference right     = null;
            SingleValueNode   leftNode  = new SingleValuePropertyAccessNode(new ConstantNode(null) /*parent*/, new EdmStructuralProperty(new EdmEntityType("MyNamespace", "MyEntityType"), "myPropertyName", left));
            SingleValueNode   rightNode = new SingleValueOpenPropertyAccessNode(new ConstantNode(null) /*parent*/, "myOpenPropertyname"); // open property's TypeReference is null
            var result = TypePromotionUtils.PromoteOperandTypes(BinaryOperatorKind.Equal, leftNode, rightNode, out left, out right);

            result.Should().BeTrue();
            left.ShouldBeEquivalentTo(HardCodedTestModel.GetPersonTypeReference());
            right.ShouldBeEquivalentTo(HardCodedTestModel.GetPersonTypeReference());
        }
        public void NotEqualsOnNullAndComplexIsSupported()
        {
            IEdmTypeReference left = null;
            IEdmTypeReference right = HardCodedTestModel.GetPersonAddressProp().Type;
            SingleValueNode leftNode = new SingleValueOpenPropertyAccessNode(new ConstantNode(null)/*parent*/, "myOpenPropertyname"); // open property's TypeReference is null
            SingleValueNode rightNode = new SingleValuePropertyAccessNode(new ConstantNode(null)/*parent*/, new EdmStructuralProperty(new EdmEntityType("MyNamespace", "MyEntityType"), "myPropertyName", right));
            var result = TypePromotionUtils.PromoteOperandTypes(BinaryOperatorKind.NotEqual, leftNode, rightNode, out left, out right);

            result.Should().BeTrue();
            left.ShouldBeEquivalentTo(HardCodedTestModel.GetPersonAddressProp().Type);
            right.ShouldBeEquivalentTo(HardCodedTestModel.GetPersonAddressProp().Type);
        }
Beispiel #15
0
        /// <summary>
        /// Bind $it to the <see cref="SingleValueOpenPropertyAccessNode"/> translated string.
        /// </summary>
        /// <param name="node">node to bind.</param>
        /// <param name="filterClauseRangeVariable">The <see cref="FilterClause"/> range variable.</param>
        /// <returns>The translated string with $it binding.</returns>
        private string BindSingleValueOpenPropertyAccess(SingleValueOpenPropertyAccessNode node, ResourceRangeVariable filterClauseRangeVariable)
        {
            string translatedNode = this.TranslateNode(node);
            ResourceRangeVariableReferenceNode rangeVariableNode = GetResourceRangeVariableReferenceNode(node);

            if (rangeVariableNode != null && IsDifferentSource(filterClauseRangeVariable, rangeVariableNode))
            {
                translatedNode = ExpressionConstants.It + ExpressionConstants.SymbolForwardSlash + translatedNode;
            }

            return(translatedNode);
        }
        public override Expression Visit(SingleValueOpenPropertyAccessNode nodeIn)
        {
            Expression source = TranslateNode(nodeIn.Source);

            if (TuplePropertyMapper == null)
            {
                return(Expression.Property(source, nodeIn.Name));
            }
            else
            {
                return(TuplePropertyMapper(source, nodeIn.Name));
            }
        }
Beispiel #17
0
        private Expression BindPropertyAccessExpression(SingleValueOpenPropertyAccessNode openNode, PropertyInfo prop)
        {
            var        source = Bind(openNode.Source);
            Expression propertyAccessExpression;

            if (QuerySettings.HandleNullPropagation == HandleNullPropagationOption.True &&
                IsNullable(source.Type) && source != _lambdaParameters[ODataItParameterName])
            {
                propertyAccessExpression = Expression.Property(RemoveInnerNullPropagation(source), prop.Name);
            }
            else
            {
                propertyAccessExpression = Expression.Property(source, prop.Name);
            }
            return(propertyAccessExpression);
        }
Beispiel #18
0
        /// <summary>
        /// Gets property for dynamic properties dictionary.
        /// </summary>
        /// <param name="openNode"></param>
        /// <returns>Returns CLR property for dynamic properties container.</returns>
        protected PropertyInfo GetDynamicPropertyContainer(SingleValueOpenPropertyAccessNode openNode)
        {
            IEdmStructuredType edmStructuredType;
            IEdmTypeReference  edmTypeReference = openNode.Source.TypeReference;

            if (edmTypeReference.IsEntity())
            {
                edmStructuredType = edmTypeReference.AsEntity().EntityDefinition();
            }
            else if (edmTypeReference.IsComplex())
            {
                edmStructuredType = edmTypeReference.AsComplex().ComplexDefinition();
            }
            else
            {
                throw Error.NotSupported(SRResources.QueryNodeBindingNotSupported, openNode.Kind, typeof(FilterBinder).Name);
            }

            return(EdmLibHelpers.GetDynamicPropertyDictionary(edmStructuredType, Model));
        }
Beispiel #19
0
        /// <summary>
        /// Bind the parent of the LambdaToken
        /// </summary>
        /// <param name="queryToken">the parent token</param>
        /// <returns>the bound parent node</returns>
        private CollectionNode BindParentToken(QueryToken queryToken)
        {
            QueryNode      parentNode           = this.bindMethod(queryToken);
            CollectionNode parentCollectionNode = parentNode as CollectionNode;

            if (parentCollectionNode == null)
            {
                SingleValueOpenPropertyAccessNode parentOpenPropertyNode =
                    parentNode as SingleValueOpenPropertyAccessNode;

                if (parentOpenPropertyNode == null)
                {
                    throw new ODataException(ODataErrorStrings.MetadataBinder_LambdaParentMustBeCollection);
                }

                // support open collection properties
                return(new CollectionOpenPropertyAccessNode(parentOpenPropertyNode.Source, parentOpenPropertyNode.Name));
            }

            return(parentCollectionNode);
        }
Beispiel #20
0
        /// <summary>
        /// Bind the parent of the LambdaToken
        /// </summary>
        /// <param name="queryToken">the parent token</param>
        /// <returns>the bound parent node</returns>
        private CollectionNode BindParentToken(QueryToken queryToken)
        {
            QueryNode      parentNode           = this.bindMethod(queryToken);
            CollectionNode parentCollectionNode = parentNode as CollectionNode;

            if (parentCollectionNode == null)
            {
                SingleValueOpenPropertyAccessNode parentOpenPropertyNode =
                    parentNode as SingleValueOpenPropertyAccessNode;

                if (parentOpenPropertyNode == null)
                {
                    throw new ODataException(ODataErrorStrings.MetadataBinder_LambdaParentMustBeCollection);
                }

                // TODO: Add support for open collection properties here by replacing
                //      with something like an OpenCollectionNode.
                throw new ODataException(ODataErrorStrings.MetadataBinder_CollectionOpenPropertiesNotSupportedInThisRelease);
            }

            return(parentCollectionNode);
        }
Beispiel #21
0
        private Expression CreateOpenPropertyAccessExpression(SingleValueOpenPropertyAccessNode openNode)
        {
            Expression sourceAccessor = BindAccessor(openNode.Source);

            // First check that property exists in source
            // It's the case when we are apply transformation based on earlier transformation
            if (sourceAccessor.Type.GetProperty(openNode.Name) != null)
            {
                return(Expression.Property(sourceAccessor, openNode.Name));
            }

            // Property doesn't exists go for dynamic properties dictionary
            PropertyInfo     prop = GetDynamicPropertyContainer(openNode);
            MemberExpression propertyAccessExpression        = Expression.Property(sourceAccessor, prop.Name);
            IndexExpression  readDictionaryIndexerExpression = Expression.Property(propertyAccessExpression,
                                                                                   DictionaryStringObjectIndexerName, Expression.Constant(openNode.Name));
            MethodCallExpression containsKeyExpression = Expression.Call(propertyAccessExpression,
                                                                         propertyAccessExpression.Type.GetMethod("ContainsKey"), Expression.Constant(openNode.Name));
            ConstantExpression nullExpression = Expression.Constant(null);

            if (QuerySettings.HandleNullPropagation == HandleNullPropagationOption.True)
            {
                var dynamicDictIsNotNull = Expression.NotEqual(propertyAccessExpression, Expression.Constant(null));
                var dynamicDictIsNotNullAndContainsKey = Expression.AndAlso(dynamicDictIsNotNull, containsKeyExpression);
                return(Expression.Condition(
                           dynamicDictIsNotNullAndContainsKey,
                           readDictionaryIndexerExpression,
                           nullExpression));
            }
            else
            {
                return(Expression.Condition(
                           containsKeyExpression,
                           readDictionaryIndexerExpression,
                           nullExpression));
            }
        }
Beispiel #22
0
 /// <summary>
 /// Translates a <see cref="SingleValueOpenPropertyAccessNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(SingleValueOpenPropertyAccessNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.Name));
 }
 /// <summary>
 /// Translates a <see cref="SingleValueOpenPropertyAccessNode"/> into a corresponding <see cref="string"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated string.</returns>
 public override string Visit(SingleValueOpenPropertyAccessNode node)
 {
     return(this.TranslatePropertyAccess(node.Source, node.Name));
 }
Beispiel #24
0
 /// <summary>
 /// Visit a SingleValueOpenPropertyAccessNode
 /// </summary>
 /// <param name="nodeIn">The node to visit</param>
 /// <returns>The translated expression</returns>
 public override Expression Visit(SingleValueOpenPropertyAccessNode nodeIn)
 {
     this.CheckArgumentNull(nodeIn, "SingleValueOpenPropertyAccessNode");
     return(this.TranslateOpenPropertyAccess(nodeIn.Source, nodeIn.Name));
 }
 public SingleValueOpenPropertyAccessNodeTests()
 {
     this.sourceNode = new ConstantNode(null);
     this.node = new SingleValueOpenPropertyAccessNode(this.sourceNode, ExpectedPropertyName);
 }
 /// <summary>
 /// Translate a SingleValueOpenPropertyAccessNode.
 /// </summary>
 /// <param name="nodeIn">The node to be translated.</param>
 /// <returns>The translated node.</returns>
 public override QueryNode Visit(SingleValueOpenPropertyAccessNode nodeIn)
 {
     return(new SingleValueOpenPropertyAccessNode(
                (SingleValueNode)nodeIn.Source.Accept(this),
                nodeIn.Name));
 }
Beispiel #27
0
 public override ImmutableList <string> Visit(SingleValueOpenPropertyAccessNode nodeIn)
 {
     return(nodeIn.Source.Accept(this).Add(nodeIn.Name));
 }
 private bool Visit(SingleValueOpenPropertyAccessNode node1, SingleValueOpenPropertyAccessNode node2)
 {
     return(node1.Name == node2.Name &&
            node1.TypeReference.IsEqual(node2.TypeReference) &&
            Compare(node1.Source, node2.Source));
 }
Beispiel #29
0
 public override int Visit(SingleValueOpenPropertyAccessNode nodeIn)
 {
     return(CombineHashCodes(TranslateNode(nodeIn.Source), nodeIn.Name.GetHashCode()));
 }
Beispiel #30
0
 public override object Visit(SingleValueOpenPropertyAccessNode nodeIn)
 {
     return(null);
 }
 public void TestInitialize()
 {
     this.sourceNode = new ConstantNode(null);
     this.node = new SingleValueOpenPropertyAccessNode(this.sourceNode, ExpectedPropertyName);
 }
 /// <summary>
 /// Visit a SingleValueOpenPropertyAccessNode
 /// </summary>
 /// <param name="nodeIn">the node to visit</param>
 /// <returns>Defined by the implementer</returns>
 public virtual T Visit(SingleValueOpenPropertyAccessNode nodeIn)
 {
     throw new NotImplementedException();
 }
 public override string Visit(SingleValueOpenPropertyAccessNode nodeIn)
 {
     return(WrapWithIdent(string.Format("OpenProperty:[{0}]", nodeIn.Name)));
 }