public CsdlSemanticsIsTypeExpression(CsdlIsTypeExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema) : base(schema, expression)
 {
     this.operandCache   = new Cache <CsdlSemanticsIsTypeExpression, IEdmExpression>();
     this.typeCache      = new Cache <CsdlSemanticsIsTypeExpression, IEdmTypeReference>();
     this.expression     = expression;
     this.bindingContext = bindingContext;
 }
Example #2
0
        /// <summary>
        /// Parse the IsOf expression using <see cref="JsonElement"/>.
        /// </summary>
        /// <param name="element">The input JSON element.</param>
        /// <param name="context">The parser context.</param>
        /// <param name="isOfExp">The built IsOf expression.</param>
        /// <returns>true/false</returns>
        private static bool BuildIsOfExpression(JsonElement element, JsonParserContext context, out CsdlIsTypeExpression isOfExp)
        {
            Debug.Assert(context != null);
            isOfExp = null;

            // Is-of expressions are represented as an object with a member $IsOf whose value is an annotation expression,
            JsonElement propertyValue;

            if (element.ValueKind != JsonValueKind.Object || !element.TryGetProperty("$IsOf", out propertyValue))
            {
                return(false);
            }

            // whose value is  an annotation expression,
            CsdlExpressionBase expression = propertyValue.ProcessProperty("$IsOf", context, ParseExpression);

            // a member $Type whose value is a string containing an qualified type name, and optionally a member $Collection with a value of true.

            // If the specified type is a primitive type or a collection of primitive types,
            // the facet members $MaxLength, $Unicode, $Precision, $Scale, and $SRID MAY be specified if applicable to the specified primitive type.
            // If the facet members are not specified, their values are considered unspecified.
            CsdlTypeReference typeReference = CsdlJsonParseHelper.ParseCsdlTypeReference(element, context);

            isOfExp = new CsdlIsTypeExpression(typeReference, expression, context.Location());
            return(true);
        }
Example #3
0
        public void ParseIsOfExpressionWorksAsExpected()
        {
            string json = @" { ""$IsOf"": {
     ""$Path"": ""FirstName""
  },
   ""$Type"": ""self.PreferredCustomer"",
   ""$Collection"": true
}";

            CsdlExpressionBase expressionBase = ParseExpression(json);

            Assert.NotNull(expressionBase);
            CsdlIsTypeExpression isTypeExp = Assert.IsType <CsdlIsTypeExpression>(expressionBase);

            Assert.NotNull(isTypeExp.Type);
            CsdlExpressionTypeReference expTypeReference = Assert.IsType <CsdlExpressionTypeReference>(isTypeExp.Type);
            CsdlCollectionType          collectionType   = Assert.IsType <CsdlCollectionType>(expTypeReference.TypeExpression);
            CsdlNamedTypeReference      namedType        = Assert.IsType <CsdlNamedTypeReference>(collectionType.ElementType);

            Assert.Equal("self.PreferredCustomer", namedType.FullName);

            Assert.NotNull(isTypeExp.Operand);
            Assert.IsType <CsdlPathExpression>(isTypeExp.Operand);
        }
 public CsdlSemanticsIsTypeExpression(CsdlIsTypeExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema)
     : base(schema, expression)
 {
     this.expression     = expression;
     this.bindingContext = bindingContext;
 }