Example #1
0
        /// <summary>
        /// Parse the <see cref="JsonElement"/> to a <see cref="IEdmReference"/>.
        /// </summary>
        /// <param name="url">The reference Url string.</param>
        /// <param name="element">The input JSON element.</param>
        /// <param name="context">The parser context.</param>
        /// <returns>null or parsed <see cref="IEdmReference"/>.</returns>
        internal static CsdlReference ParseReference(string url, JsonElement element, JsonParserContext context)
        {
            // The value of each reference object is an object.
            if (!element.ValidateValueKind(JsonValueKind.Object, context))
            {
                return(null);
            }

            IList <CsdlInclude>            includes           = null;
            IList <CsdlIncludeAnnotations> includeAnnotations = null;
            IList <CsdlAnnotation>         annotations        = new List <CsdlAnnotation>();

            element.ParseAsObject(context, (propertyName, propertyValue) =>
            {
                // The reference object MAY contain the members $Include and $IncludeAnnotations as well as annotations.
                switch (propertyName)
                {
                case "$Include":
                    // The value of $Include is an array.
                    // Array items are objects that MUST contain the member $Namespace and MAY contain the member $Alias.
                    includes = propertyValue.ParseAsArray(context, ParseInclude);
                    break;

                case "$IncludeAnnotations":
                    // The value of $IncludeAnnotations is an array.
                    // Array items are objects that MUST contain the member $TermNamespace and MAY contain the members $Qualifier and $TargetNamespace.
                    includeAnnotations = propertyValue.ParseAsArray(context, ParseIncludeAnnotations);
                    break;

                default:
                    // The reference objects MAY contain annotations.
                    SchemaJsonParser.ParseCsdlAnnotation(propertyName, propertyValue, context, annotations);
                    break;
                }
            });

            CsdlReference reference = new CsdlReference(url,
                                                        includes ?? Enumerable.Empty <CsdlInclude>(),
                                                        includeAnnotations ?? Enumerable.Empty <CsdlIncludeAnnotations>(),
                                                        context.Location());

            annotations.ForEach(a => reference.AddAnnotation(a));
            return(reference);
        }
Example #2
0
        /// <summary>
        /// Build the JSON value <see cref="JsonElement"/> to collection of <see cref="IEdmReference"/>.
        /// It's weird that we parse it into IEdmReference, not CsdlReference.
        /// It is because CsdlModel needs "IEdmReference". :-(
        /// </summary>
        /// <param name="element">The input JSON element.</param>
        /// <param name="jsonPath">The parser context.</param>
        /// <returns>null or parsed collection of <see cref="IEdmReference"/>.</returns>
        internal static IList <CsdlReference> ParseReferences(JsonElement element, JsonParserContext context)
        {
            // The value of $Reference is an object that contains one member per referenced CSDL document.
            if (!element.ValidateValueKind(JsonValueKind.Object, context))
            {
                return(null);
            }

            IList <CsdlReference> references = new List <CsdlReference>();

            element.ParseAsObject(context, (url, propertyValue) =>
            {
                CsdlReference reference = ParseReference(url, propertyValue, context);
                if (reference != null)
                {
                    references.Add(reference);
                }
            });

            return(references);
        }
Example #3
0
 public CsdlSemanticsReference(CsdlSemanticsModel model, CsdlReference reference)
     : base(reference)
 {
     this.model     = model;
     this.reference = reference;
 }