Example #1
0
        /// <summary>
        /// Searches for vocabulary annotations specified by this model.
        /// </summary>
        /// <param name="element">The annotated element.</param>
        /// <returns>The vocabulary annotations for the element.</returns>
        public override IEnumerable <IEdmVocabularyAnnotation> FindDeclaredVocabularyAnnotations(IEdmVocabularyAnnotatable element)
        {
            // Include the inline annotations only if this model is the one that defined them.
            CsdlSemanticsElement semanticsElement = element as CsdlSemanticsElement;
            IEnumerable <IEdmVocabularyAnnotation> inlineAnnotations = semanticsElement != null && semanticsElement.Model == this ? semanticsElement.InlineVocabularyAnnotations : Enumerable.Empty <IEdmVocabularyAnnotation>();

            List <CsdlSemanticsAnnotations> elementAnnotations;
            string fullName = EdmUtil.FullyQualifiedName(element);

            if (fullName != null && this.outOfLineAnnotations.TryGetValue(fullName, out elementAnnotations))
            {
                List <IEdmVocabularyAnnotation> result = new List <IEdmVocabularyAnnotation>();

                foreach (CsdlSemanticsAnnotations annotations in elementAnnotations)
                {
                    foreach (CsdlAnnotation annotation in annotations.Annotations.Annotations)
                    {
                        IEdmVocabularyAnnotation vocabAnnotation = this.WrapVocabularyAnnotation(annotation, annotations.Context, null, annotations, annotations.Annotations.Qualifier);
                        vocabAnnotation.SetSerializationLocation(this, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
                        result.Add(vocabAnnotation);
                    }
                }

                return(inlineAnnotations.Concat(result));
            }

            return(inlineAnnotations);

            // TODO: REF
            // find annotation in referenced models
        }
Example #2
0
        internal IEnumerable <IEdmVocabularyAnnotation> WrapInlineVocabularyAnnotations(CsdlSemanticsElement element, CsdlSemanticsSchema schema)
        {
            IEdmVocabularyAnnotatable targetContext = element as IEdmVocabularyAnnotatable;

            if (targetContext != null)
            {
                IEnumerable <CsdlVocabularyAnnotationBase> vocabularyAnnotations = element.Element.VocabularyAnnotations;
                if (vocabularyAnnotations.FirstOrDefault <CsdlVocabularyAnnotationBase>() != null)
                {
                    List <IEdmVocabularyAnnotation> list = new List <IEdmVocabularyAnnotation>();
                    foreach (CsdlVocabularyAnnotationBase base2 in vocabularyAnnotations)
                    {
                        IEdmVocabularyAnnotation annotation = this.WrapVocabularyAnnotation(base2, schema, targetContext, null, base2.Qualifier);
                        annotation.SetSerializationLocation(this, 0);
                        list.Add(annotation);
                    }
                    return(list);
                }
            }
            return(Enumerable.Empty <IEdmVocabularyAnnotation>());
        }
Example #3
0
        internal IEnumerable <IEdmVocabularyAnnotation> WrapInlineVocabularyAnnotations(CsdlSemanticsElement element, CsdlSemanticsSchema schema)
        {
            IEdmVocabularyAnnotatable vocabularyAnnotatableElement = element as IEdmVocabularyAnnotatable;

            if (vocabularyAnnotatableElement != null)
            {
                IEnumerable <CsdlAnnotation> vocabularyAnnotations = element.Element.VocabularyAnnotations;
                if (vocabularyAnnotations.FirstOrDefault() != null)
                {
                    List <IEdmVocabularyAnnotation> wrappedAnnotations = new List <IEdmVocabularyAnnotation>();
                    foreach (CsdlAnnotation vocabularyAnnotation in vocabularyAnnotations)
                    {
                        IEdmVocabularyAnnotation vocabAnnotation = this.WrapVocabularyAnnotation(vocabularyAnnotation, schema, vocabularyAnnotatableElement, null, vocabularyAnnotation.Qualifier);
                        vocabAnnotation.SetSerializationLocation(this, EdmVocabularyAnnotationSerializationLocation.Inline);
                        wrappedAnnotations.Add(vocabAnnotation);
                    }

                    return(wrappedAnnotations);
                }
            }

            return(Enumerable.Empty <IEdmVocabularyAnnotation>());
        }
Example #4
0
 public static void AddVocabularyAnnotation(this EdmModel model, IEdmVocabularyAnnotation annotation, EdmVocabularyAnnotationSerializationLocation location)
 {
     model.AddVocabularyAnnotation(annotation);
     annotation.SetSerializationLocation(model, location);
 }