Exemplo n.º 1
0
 private static void CopyAnnotations(AnnotatedItem item, IList <Annotation> annotations)
 {
     foreach (var annotation in annotations)
     {
         var cloneableAnn = annotation as IDeepCloneableAnnotation;
         var newAnn       = cloneableAnn == null ? annotation : cloneableAnn.DeepClone();
         item.Annotations.Add(newAnn);
     }
 }
 /// <summary>
 /// Converts mime type annotations from xml annotation to MimeType annotation
 /// </summary>
 /// <param name="annotatedItem">item to convert annotation on</param>
 private void ConvertMimeTypeAnnotations(AnnotatedItem annotatedItem)
 {
     ExceptionUtilities.CheckArgumentNotNull(annotatedItem, "annotatedItem");
     var mimeTypeAnnotation = annotatedItem.Annotations.OfType<AttributeAnnotation>()
         .Where(ann => ann.Content.Name.LocalName.Equals("MimeType", StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
     if (mimeTypeAnnotation != null)
     {
         annotatedItem.Add(new MimeTypeAnnotation(mimeTypeAnnotation.Content.Value));
     }
 }
        private static void AddAnnotationIfDoesntExist(AnnotatedItem payload, AttributeAnnotation annotation)
        {
            var exists = payload.Annotations.OfType<AttributeAnnotation>().Any(a =>
            {
                ExceptionUtilities.CheckObjectNotNull(a.Content, "Content expected for attribute");
                return a.Content.Name.Equals(annotation.Content.Name);
            });

            if (!exists)
            {
                payload.Annotations.Add(annotation);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses an annotation element/attribute in the csdl/ssdl file.
        /// </summary>
        /// <param name="annotatedItem">the annotated item to add annotations to</param>
        /// <param name="xmlElement">the element to parse</param>
        protected void ParseAnnotations(AnnotatedItem annotatedItem, XElement xmlElement)
        {
            foreach (XElement element in xmlElement.Elements())
            {
                if (this.IsXsdlElement(element, "Documentation"))
                {
                    annotatedItem.Annotations.Add(this.ParseDocumentationAnnotation(element));
                    continue;
                }

                if (!this.IsXsdlNamespace(element.Name.NamespaceName))
                {
                    annotatedItem.Annotations.Add(new StructuralAnnotation { Content = element });
                }
            }

            foreach (XAttribute attrib in xmlElement.Attributes())
            {
                if (attrib.Name.NamespaceName == EdmConstants.CodegenNamespace)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(attrib.Name.NamespaceName))
                {
                    annotatedItem.Annotations.Add(new AttributeAnnotation { Content = attrib });
                    continue;
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Removes an annotation of type T from a property.
 /// </summary>
 /// <param name="property">The property.</param>
 private static void RemoveVirtualAnnotationFromProperty(AnnotatedItem property)
 {
     foreach (var annotation in property.Annotations.OfType<VirtualAnnotation>().ToArray())
     {
         property.Annotations.Remove(annotation);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Annotates a property with Annotation of type T
 /// </summary>
 /// <param name="property">The property.</param>
 private static void AnnotatePropertyAsVirtual(AnnotatedItem property)
 {
     if (!property.Annotations.Any(a => a is VirtualAnnotation))
     {
         property.Annotations.Add(new VirtualAnnotation());
     }
 }
        private void ConvertAnnotations(AnnotatedItem annotatedItem)
        {
            for (int index = 0; index < annotatedItem.Annotations.Count; index++)
            {
                var annotation = annotatedItem.Annotations[index];

                var structuralAnnotation = annotation as StructuralAnnotation;
                if (structuralAnnotation != null)
                {
                    annotatedItem.Annotations[index] = this.ConvertSingleAnnotation(structuralAnnotation);
                }

                var attributeAnnotation = annotation as AttributeAnnotation;
                if (attributeAnnotation != null)
                {
                    annotatedItem.Annotations[index] = this.ConvertSingleAnnotation(attributeAnnotation);
                }
            }
        }
 /// <summary>
 /// Visits an annotated item
 /// </summary>
 /// <param name="item">item to visit</param>
 protected virtual void VisitAnnotatedItem(AnnotatedItem item)
 {
     // do nothing
 }
        /// <summary>
        /// Generates the documentation element for given annotated item.
        /// </summary>
        /// <param name="xmlNamespace">The XML namespace.</param>
        /// <param name="annotatedItem">The annotated item.</param>
        /// <returns>Documentation XElement or null if <see cref="DocumentationAnnotation" /> is not present on the item.</returns>
        protected virtual XElement GenerateDocumentation(XNamespace xmlNamespace, AnnotatedItem annotatedItem)
        {
            var documentationAnnotation = annotatedItem.Annotations.OfType<DocumentationAnnotation>().SingleOrDefault();
            if (documentationAnnotation == null)
            {
                return null;
            }

            var element = new XElement(xmlNamespace + "Documentation");
            if (documentationAnnotation.Summary != null)
            {
                element.Add(new XElement(xmlNamespace + "Summary", documentationAnnotation.Summary));
            }

            if (documentationAnnotation.LongDescription != null)
            {
                element.Add(new XElement(xmlNamespace + "LongDescription", documentationAnnotation.LongDescription));
            }

            return element;
        }
Exemplo n.º 10
0
 private static void AddCollectionContractTypeAnnotation(AnnotatedItem item, DataType dataType)
 {
     var collectionDataType = dataType as CollectionDataType;
     if (collectionDataType != null)
     {
         if (collectionDataType.ElementDataType is PrimitiveDataType)
         {
             item.Annotations.Add(new CollectionContractTypeAnnotation() { FullTypeName = "IEnumerable", IsGeneric = true });
         }
         else
         {
             item.Annotations.Add(new CollectionContractTypeAnnotation() { FullTypeName = "IEnumerable", IsGeneric = true });
         }
     }
 }