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);
            }
        }
        private Annotation ConvertSingleAnnotation(AttributeAnnotation annotation)
        {
            if (annotation.Content == null)
            {
                return annotation;
            }

            if (annotation.Content.Name.Namespace == EdmConstants.AnnotationNamespace && annotation.Content.Name.LocalName == "StoreGeneratedPattern")
            {
                if (annotation.Content.Value == StoreGeneratedPatternAnnotation.None.Name)
                {
                    return StoreGeneratedPatternAnnotation.None;
                }
                else if (annotation.Content.Value == StoreGeneratedPatternAnnotation.Identity.Name)
                {
                    return StoreGeneratedPatternAnnotation.Identity;
                }
                else
                {
                    ExceptionUtilities.Assert(annotation.Content.Value == StoreGeneratedPatternAnnotation.Computed.Name, "Unrecognized store generated annotation: '{0}'", annotation.Content.Value);
                    return StoreGeneratedPatternAnnotation.Computed;
                }
            }

            if (annotation.Content.Name.Namespace != EdmConstants.TaupoAnnotationsNamespace)
            {
                return annotation;
            }

            Type annotationType = this.FindAnnotationType(annotation.Content.Name);
            if (annotationType == null)
            {
                return annotation;
            }

            // if the type can do custom serialization...
            if (typeof(ICustomAnnotationSerializer).IsAssignableFrom(annotationType))
            {
                // since this interface is implemented, we also expect a constructor
                // which takes an XAttribute to be there, so let's just invoke it
                // on our XAttribute
                return (Annotation)Activator.CreateInstance(annotationType, annotation.Content);
            }

            // if it is a tag, just create instance of that class
            if (typeof(TagAnnotation).IsAssignableFrom(annotationType))
            {
                return (Annotation)Activator.CreateInstance(annotationType);
            }

            // otherwise return the original 
            return annotation;
        }