示例#1
0
 public CsdlSemanticsApplyExpression(CsdlApplyExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema)
     : base(schema, expression)
 {
     this.expression     = expression;
     this.bindingContext = bindingContext;
     this.schema         = schema;
 }
 public CsdlSemanticsApplyExpression(CsdlApplyExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema) : base(schema, expression)
 {
     this.appliedFunctionCache = new Cache <CsdlSemanticsApplyExpression, IEdmExpression>();
     this.argumentsCache       = new Cache <CsdlSemanticsApplyExpression, IEnumerable <IEdmExpression> >();
     this.expression           = expression;
     this.bindingContext       = bindingContext;
     this.schema = schema;
 }
示例#3
0
        /// <summary>
        /// Parse the Apply expression using <see cref="JsonElement"/>.
        /// </summary>
        /// <param name="element">The input JSON element.</param>
        /// <param name="context">The parser context.</param>
        /// <param name="applyExp">The built apply expression.</param>
        /// <returns>true/false.</returns>
        private static bool TryParseApplyExpression(JsonElement element, JsonParserContext context, out CsdlApplyExpression applyExp)
        {
            Debug.Assert(context != null);
            applyExp = null;

            // Apply expressions are represented as an object with a member $Apply whose value is an array
            JsonElement propertyValue;

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

            // whose value is an array of annotation expressions,
            IList <CsdlExpressionBase> arguments = propertyValue.ProcessArrayProperty("$Apply", context, ParseExpression);

            // a member $Function whose value is a string containing the qualified name of the client-side function to be applied.
            string functionName = element.ProcessRequiredProperty("$Function", context, (e, c) => e.ParseAsString(c));

            applyExp = new CsdlApplyExpression(functionName, arguments, context.Location());
            return(true);
        }
示例#4
0
        public void ParseApplyExpressionWorksAsExpected()
        {
            string json = @" {
""$Apply"": [
    ""Product: "",
    {
                ""$Path"": ""ProductName""
    },
    ""("",
    {
               ""$Path"": ""Available/Quantity""
    },
    "" "",
    {
                ""$Path"": ""Available /Unit""
    },
    "" available)""
  ],
  ""$Function"": ""odata.concat""
}";

            CsdlExpressionBase expressionBase = ParseExpression(json);

            Assert.NotNull(expressionBase);
            CsdlApplyExpression applyExp = Assert.IsType <CsdlApplyExpression>(expressionBase);

            Assert.NotNull(applyExp.Function);
            Assert.Equal("odata.concat", applyExp.Function);

            Assert.NotNull(applyExp.Arguments);
            Assert.Equal(7, applyExp.Arguments.Count());

            // 0
            CsdlConstantExpression constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(0));

            Assert.Equal("Product: ", constantArgument.Value);

            // 1
            CsdlPathExpression pathArgument = Assert.IsType <CsdlPathExpression>(applyExp.Arguments.ElementAt(1));

            Assert.Equal("ProductName", pathArgument.Path);

            // 2
            constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(2));
            Assert.Equal("(", constantArgument.Value);

            // 3
            pathArgument = Assert.IsType <CsdlPathExpression>(applyExp.Arguments.ElementAt(3));
            Assert.Equal("Available/Quantity", pathArgument.Path);

            // 4
            constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(4));
            Assert.Equal(" ", constantArgument.Value);

            // 5
            pathArgument = Assert.IsType <CsdlPathExpression>(applyExp.Arguments.ElementAt(5));
            Assert.Equal("Available /Unit", pathArgument.Path);

            // 6
            constantArgument = Assert.IsType <CsdlConstantExpression>(applyExp.Arguments.ElementAt(6));
            Assert.Equal(" available)", constantArgument.Value);
        }