/// <summary>
        /// Remove all existing annotations of type <typeparamref name="T"/> and set <paramref name="annotation"/>.
        /// </summary>
        /// <typeparam name="T">The type of the annotation to set.</typeparam>
        /// <param name="payloadElement">The payload element to set the annotation on.</param>
        /// <param name="annotation">The annotation to set.</param>
        /// <returns>The <paramref name="payloadElement"/> with the <paramref name="annotation"/> set.</returns>
        public static T SetAnnotation <T>(this T payloadElement, ODataPayloadElementAnnotation annotation) where T : ODataPayloadElement
        {
            ExceptionUtilities.CheckArgumentNotNull(annotation, "annotation");

            payloadElement.RemoveAnnotations(annotation.GetType());
            payloadElement.AddAnnotation(annotation);
            return(payloadElement);
        }
        private bool CompareAnnotation(ODataPayloadElementAnnotation expectedAnnotation, ODataPayloadElementAnnotation observedAnnotation, out string errorMessage)
        {
            try
            {
                errorMessage = null;
                this.Assert.AreEqual(expectedAnnotation.GetType(), observedAnnotation.GetType(), "Annotation types should be same");
                if (expectedAnnotation is XmlTreeAnnotation)
                {
                    XmlTreeAnnotation e = expectedAnnotation as XmlTreeAnnotation;
                    XmlTreeAnnotation o = observedAnnotation as XmlTreeAnnotation;
                    this.Assert.IsNotNull(o, "Observed annotation cannot be null");
                    this.Assert.AreEqual(e.LocalName, o.LocalName, "Local names should match");
                    this.Assert.AreEqual(e.NamespaceName, o.NamespaceName, "Namespace names should be equal");
                    this.Assert.AreEqual(e.PropertyValue, o.PropertyValue, "Property values must be equal");
                    this.Assert.AreEqual(e.IsAttribute, o.IsAttribute, "IsAttribute values should be equal");
                    this.Assert.AreEqual(e.Children.Count, o.Children.Count, "Children count must be equal");
                    Compare(e.Children.Cast <ODataPayloadElementAnnotation>().ToList(), o.Children.Cast <ODataPayloadElementAnnotation>().ToList());
                }
                else if (expectedAnnotation is SelfLinkAnnotation)
                {
                    SelfLinkAnnotation e = expectedAnnotation as SelfLinkAnnotation;
                    SelfLinkAnnotation o = observedAnnotation as SelfLinkAnnotation;
                    this.Assert.IsNotNull(o, "Observed annotation cannot be null");
                    this.Assert.AreEqual(e.Value, o.Value, "Values should match");
                }
                else if (expectedAnnotation is ContentTypeAnnotation)
                {
                    ContentTypeAnnotation e = expectedAnnotation as ContentTypeAnnotation;
                    ContentTypeAnnotation o = observedAnnotation as ContentTypeAnnotation;
                    this.Assert.IsNotNull(o, "Observed annotation cannot be null");
                    this.Assert.AreEqual(e.Value, o.Value, "Values should match");
                }

                return(true);
            }
            catch (DataComparisonException e)
            {
                errorMessage = "Message: " + e.Message + " Exception type:" + e.GetType() + " Stack:" + e.StackTrace;
                return(false);
            }
        }