示例#1
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);
        }
示例#2
0
        /// <summary>
        /// Parse the Cast expression using <see cref="JsonElement"/>.
        /// </summary>
        /// <param name="element">The input JSON element.</param>
        /// <param name="context">The parser context.</param>
        /// <param name="castExp">The built cast expression.</param>
        /// <returns>true/false.</returns>
        private static bool TryParseCastExpression(JsonElement element, JsonParserContext context, out CsdlCastExpression castExp)
        {
            Debug.Assert(context != null);

            castExp = null;
            // Cast expressions are represented as an object with a member $Cast
            JsonElement propertyValue;

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

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

            // a member $Type whose value is a string containing the qualified type name, and optionally a member $Collection with a value of true.
            CsdlTypeReference typeReference = CsdlJsonParseHelper.ParseCsdlTypeReference(element, context);

            castExp = new CsdlCastExpression(typeReference, expression, context.Location());
            return(true);
        }